Diagnostic

Tracing

Default framework’s diagnostic subsystem allows to store all the major application events into a database and do postmortem analysis or review application workflow, performance, etc. At the moment, trace subsystem is implemented and the following are the most important interfaces:

  • ITrace – represents a tracer for tracing subsystem 

     The interface defines the behavior of logging trace records of different types:

  • Info
  • Warn
  • Error
  • Fatal

You can interpret these types in program as you wish

  • ITraceCategory – represents a trace category which helps to group trace records
  • TraceRecord – represents a single trace record

Usage of tracing

You can use the default implementation of tracing which logs trace messages into local database and/or add your custom one. The following section in your application.config file should be defined:

<diagnostic>
      <!-- trace subsystem-->
      <traces>
        <trace name="default" type="PhoneCore.Framework.Diagnostic.Tracing.DefaultTrace, PhoneCore.Framework">
          <storage connectionString="Data Source=isostore:/tracedb.sdf">
            <init>
              <types>
                <type name="Info" />
                <type name="Warn" />
                <type name="Error" />
                <type name="Fatal" />
              </types>
            </init>
          </storage>
          <level>0</level>
          <controller type="PhoneCore.Framework.Diagnostic.Tracing.DefaultTraceController, PhoneCore.Framework" 
                      template="Resources/Templates/DefaultTraceReport.txt" />
        </trace>
      </traces>
    </diagnostic> 

PhoneCore framework will create the list of traces define here.

After the definition of the traces in configuration, you can use it using the TraceFactory class which exposes two static methods to access the configured traces:

  • GetTrace() – returns default trace
  • GetTrace(string name) – returns trace by name
  • GetTraceCategory(string name) – returns trace category

Here is the example of trace usage:

 

private static readonly ITrace _trace = TraceFactory.GetTrace();
private static readonly ITraceCategory _categoryTo = TraceFactory.GetTraceCategory("Navigation.To");
_trace.Info(_categoryTo, String.Format("Navigate to {0}", pageUri)); 
This code uses the default trace which writes Info message using "Navigation.To" category which will create automatically at the first call of TraceCategory.GetInstance()The another way to get trace is use container:

 
_trace = container.Resolve<ITrace>();
 _category = container.Resolve<ITraceCategory>("FileSystemService");
This is possible because the core bootstrapper registers these services at startup. Here is the sample of results:

Trace

Last edited Feb 11, 2012 at 9:18 PM by Ilya_Builuk, version 8

Comments

No comments yet.