Overview

The ReflectInsight Semantic Logging Extension is a custom sink specifically developed for the Semantic Logging Framework. The Semantic Logging Framework was developed to tap into the ETW infrastructure and in doing so developers can redirect ETW messages to their preferred destinations (i.e. Viewer, etc.).

This document will show you how to setup and configure, with the ReflectInsight Semantic Logging Extension (Sink) for both “In-Process” and “Out-of-Process” implementations.

In-Process: Step-by-Step

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

Download

2. Download the ReflectInsight Extension Binaries or Source and rebuild if necessary. Alternatively you can use the NuGet package. See below for details on the NuGet package.

NOTE: If you have added the Semantic Logging Extension from the NuGet gallery, then you can skip step #3 as it's already done for you.

3. Once you have the ReflectInsight Extensions, go to your project in Visual Studio and add a reference to:
  • ReflectSoftware.Insight.dll
  • ReflectSoftware.Insight.Extensions.SemanticLogging.dll.
SemanticLogging_Adding_Assembly.png

NOTE: At this time, Semantic Logging doesn’t offer the ability to configure the “In-Process” method via configuration files. We are not sure if this was by design or just a temporary limitation until their next release.

4. The following section will show code examples on how to bind to the ReflectInsight Logging Framework.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics.Tracing;
 
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging;
using ReflectSoftware.Insight.Extensions.SemanticLogging;
 
namespace Sample.SemanticLogging
{
    class Program
    {
        static void DoSomeLogging()
        {
            // log your events
            MyFirstEventSource.Log.SomeSimple("Hello, world", "Hey");
            MyFirstEventSource.Log.SomeEvent1("Hello, world", 10);
            MyFirstEventSource.Log.SomeError("This is a test from {0}", 20);
            MyFirstEventSource.Log.SomeError2("This is a test from {0}", 30);
            MyFirstEventSource.Log.SomeCritical("This is a test from {0}", 40);
            MyFirstEventSource.Log.SomeWarning("This is a test from {0}", 50);
            MyFirstEventSource.Log.SomeVerbose("This is a test from {0}", 60);
        }
        
        static void InProcessMethod1()
        {
            const String messagePattern = null; // "%message% - %eventid%, %opcode%, %eventname%, %providerid%";

            // application start: create and initalize listeners
            ObservableEventListener logListener = new ObservableEventListener();
 
            logListener.EnableEvents(MyFirstEventSource.Log, EventLevel.Verbose, MyFirstEventSource.Keywords.Other | MyFirstEventSource.Keywords.Keyword1);
	   logListener.LogToReflectInsight(messagePattern: messagePattern);
            logListener.LogToConsole();
            
            DoSomeLogging();
 
            // application end: create and initalize listeners
            logListener.DisableEvents(MyFirstEventSource.Log);            
            logListener.Dispose();
        }
 
        static void InProcessMethod2()
        {
            // application start: create and initalize listeners
            EventListener logListener1 = RIEventLog.CreateListener();
            EventListener logListener2 = ConsoleLog.CreateListener();
 
            logListener1.EnableEvents(MyFirstEventSource.Log, EventLevel.Verbose, MyFirstEventSource.Keywords.Other | MyFirstEventSource.Keywords.Keyword1);
            logListener2.EnableEvents(MyFirstEventSource.Log, EventLevel.Verbose, MyFirstEventSource.Keywords.Other | MyFirstEventSource.Keywords.Keyword1);
 
            DoSomeLogging();
 
            // application end: create and initalize listeners
            logListener1.DisableEvents(MyFirstEventSource.Log);
            logListener2.DisableEvents(MyFirstEventSource.Log);
 
            logListener1.Dispose();
            logListener2.Dispose();
        }
 
        static void OutProcessMethod()
        {
            /* For the OutProcess Method you must install and setup the 
             * SemanticLogging Service to listen for your EventSources.
             * Please refer to the Enterprise Library documentation on how to 
             * setup and configure. 
             * A sample *.svc.xml has been attached to this sample on how 
             * to configure The ReflectSoftware.Insight.Extensions.SemanticLogging
             */
            DoSomeLogging();
        }
                
        static void Main(string[] args)
        {
            InProcessMethod1();
            //InProcessMethod2();
            //OutProcessMethod();
        }
    }
}

Out-of-Process: Step-by-Step

It is assumed that the “Enterprise Library Semantic Logging Out-of-Process Service” has been installed. For more information on how to install this service, please consult the “Enterprise Library” documentation.

1. Download latest Binaries from our CodePlex site. Before extracting the Libraries from the ZIP file, please insure that you “Unblock” all contents. See screenshot below:

SemanticLogging_Unblock_ZipContents.png

2. Open up the Service MMC and Stop the Semantic Logging Out-of-Process service.

3. Copy the following ReflectInsight required libraries from the NET4.5 directory into the directory where the Semantic Logging Out-of-Process service was installed:
  • RabbitMQ.Client.dll
  • ReflectSoftware.Insight.dll
  • ReflectSoftware.Insight.Extensions.SemanticLogging.dll

4. Create a file called ReflectInsight.config and insure that the basic ReflectInsight configuration elements have been configured:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <insightSettings>
    <listenerGroups active="Release">
      <group name="Release" enabled="true" maskIdentities="false">
        <destinations>
          <destination name="Viewer" enabled="true" filter="" details="Viewer" />
        </destinations>
      </group>      
    </listenerGroups>
    <logManager default="semantic">      
      <instance name="semantic" category="Semantic" />
    </logManager>
  </insightSettings>
</configuration>

5. Locate and open the service’s configuration called SemanticLogging-svc.exe.config and insure that the following elements have been configured:

<configSections>
    <section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight" />
  </configSections>
 
  <insightSettings externalConfigSource="ReflectInsight.config"/>
</configSections>

6. Locate and open the service’s configuration called SemanticLogging-svc.xml and insure that the following elements have been configured:

<sinks>
    <!-- The service identity should have security permissions to access the resource according to each event sink -->
    <!--[Add any built-in or custom sink definition here]-->    		<customSink name="RIEventSink" type ="ReflectSoftware.Insight.Extensions.SemanticLogging.RIEventSink, ReflectSoftware.Insight.Extensions.SemanticLogging">
      <sources>
        <eventSource name="MyFirstEventSource" level="LogAlways" />
      </sources>
      <parameters>
        <!-- messagePattern: 
              %providerid%
              %eventid%
              %keywords%
              %level%
              %message%
              %opcode%
              %task%
              %version%
              %payload%
              %eventname%
              %timestamp%
              
              example patterns:
                  messagePattern1: %message% - %payload%
                  messagePattern2: %message% - %payload%
                  messagePattern3: %message% - %eventid%, %opcode%, %eventname%, %providerid%
        -->
        <parameter name="instanceName" type="System.String" value="semantic" />
        <parameter name="messagePattern" type="System.String" value="%message% -  %eventid%, %opcode%, %payload%" />
        <parameter name="timeFormat" type="System.String" value="yyyy-MM-ddTHH:mm:ss.fffffffZ" />
      </parameters>
    </customSink>
  </sinks>

7. Start the Semantic Logging Out-of-Process service.

8. All that you need to do is start logging messages. Note, if your application is only using the Out-of-Process method, then there is no need to add any ReflectInsight references to you application.

static void DoSomeLogging()
        {
            // log your events
            MyFirstEventSource.Log.SomeSimple("Hello, world", "Hey");
            MyFirstEventSource.Log.SomeEvent1("Hello, world", 10);
            MyFirstEventSource.Log.SomeError("This is a test from {0}", 20);
            MyFirstEventSource.Log.SomeError2("This is a test from {0}", 30);
            MyFirstEventSource.Log.SomeCritical("This is a test from {0}", 40);
            MyFirstEventSource.Log.SomeWarning("This is a test from {0}", 50);
            MyFirstEventSource.Log.SomeVerbose("This is a test from {0}", 60);
        }

9. That's it, you're done!

NuGet Package

We've created a NuGet package for our SemanticLogging extension. You can find it over on Nuget.

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

sshot-504.png

Last edited Jul 17, 2013 at 2:33 AM by RSDeveloper, version 5