Overview

We've added support for the PostSharp tracer. This allows you to leverage your current investment in PostSharp, but leverage the power and flexibility that comes with the ReflectInsight viewer. You can view your PostSharp messages in realtime, in a rich viewer that allows you to filter out and search for what really matters to you.

The benefits of using the PostSharp extension gives you automatic traceability across all methods at a class level or only at a specific method, or a specific field. If using the extension at a class level there are cases where may want to ignore certain methods ie. constructor. You can also define if method traceability will log parameters and their values. At a field level traceability, changing field values will can be shown in the Viewer's Scratchpad and/or Log Window.

PostSharp Configuration

1. Download and install the ReflectInsight Viewer. You will need this installed to view your messages from the ReflectInsight Logging Extensions.

Download

2. Then make sure you have PostSharp installed and configured in Visual Studio. You can download PostSharp from http://www.postsharp.net/.

3. After you have PostSharp installed, you can use NuGet Package Manager Console or UI to get the ReflectSoftware.Insight.Extensions.PostSharp extension.

Using the Package Manager Console:

To install ReflectSoftware.Insight.Extensions.PostSharp extension, run the following command in the Package Manager Console.

sshot-462.png

Using the Manage NuGet Packages UI:

Right click on your project and go to the Manage NuGet Packages menu item...

sshot-466.png

4. The next step is to configure your app or web configuration file and incorporate the ReflectInsight appender. If you don't already have an App.config or Web.config, add it. Then open the configuration file and add a new ConfigSection as shown here:

<configuration>
  <configSections>    
    <section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight" />
  </configSections>
</configuration>
5. Now you will need to add the InsightSettings section. You can get started with the following simple configuration:

<configuration>
  <insightSettings>
    <baseSettings>
      <configChange enabled="true"/>      
      <propagateException enabled="false"/>      
      <exceptionEventTracker time="20"/>
      <debugMessageProcess enabled="true" />
    </baseSettings>

    <listenerGroups active="Debug">
      <group name="Debug" enabled="true" maskIdentities="false">
        <destinations>
          <destination name="Viewer" enabled="true" filter="" details="Viewer"/>
        </destinations>
      </group>
    </listenerGroups>
    
    <logManager>      
      <!-- used by the PostSharp Tracer Test -->
      <instance name="fields"/>
      <instance name="serviceClass" category="ServiceLayer"/>
      <instance name="businessClass" category="BusinessLayer"/>
      <instance name="dataAccessClass" category="DataAccessLayer"/>
    </logManager>

<!-- tracer properties = "None|MethodName|Parameters|HashedParameters|IgnoreExceptions" - default: MethodName
    
    None - will get nothing
    MethodName - will only show method name without parameters ( default )
    Parameters - will show method name and parameters but only for primitve types
    HashedParameters - will show method name but hash all parameter values
    IgnoreExceptions - will ignore logging exceptions between enter/exit block    
-->
    
    <extensions>
      <extension name="tracer.fields" instance="fields"/>
      <extension name="tracer.service" instance="serviceClass" properties="MethodName"/>
      <extension name="tracer.business" instance="businessClass" properties="Parameters"/>
      <extension name="tracer.dataAccess" instance="dataAccessClass" properties="HashedParameters"/>
    </extensions>
  </insightSettings>
</configuration>

6. In your code, add this include statement below

using ReflectSoftware.Insight.Extensions.PostSharp;

7. Example with a copy

using ReflectSoftware.Insight.Extensions.PostSharp;
[RITrace("tracer.sectionB")]
static public class TraceBusiness
{
    //---------------------------------------------------------------------        
    [RITraceAttribute(AttributeExclude = true)]
    static TraceBusiness()
    { }

    //---------------------------------------------------------------------         
    static public String Business1(String name, Byte[] data1, Int32 age, List<String> data2)
    {
        IRITrace tracer = RITraceManager.GetActiveTracer();
        tracer.Logger.AddCheckpoint();
        tracer.Logger.SendMsg("This is message one in: {0}", tracer.Name);
        tracer.Logger.SendNote("This is message two in: {0}", tracer.Name);
        TraceDataAccess.DataAccess(name);
        tracer.Logger.SendDebug("This is message three in: {0}", tracer.Name);
        tracer.Logger.SendWarning("This is message four in: {0}", tracer.Name);
        return "Some String value";
    }
}

8. Example with a method

using ReflectSoftware.Insight.Extensions.PostSharp;

static public class TraceDataAccess
{
    [RITrace("tracer.sectionC")]
    //---------------------------------------------------------------------                 
    static public void DataAccess(String name)
    {
        IRITrace tracer = RITraceManager.GetActiveTracer();
        tracer.Logger.AddCheckpoint();
        tracer.Logger.SendMsg("This is message one in: {0}", tracer.Name);
        tracer.Logger.SendNote("This is message two in: {0}", tracer.Name);
        if (name == "trigger")
            throw new Exception("Trigger threw an exception!");

        tracer.Logger.SendDebug("This is message three in: {0}", tracer.Name);
        tracer.Logger.SendWarning("This is message four in: {0}", tracer.Name);
    }
}

Last edited Jul 22, 2013 at 4:09 AM by RSDeveloper, version 44