Enterprise Library 6, Semantic Logging, Part 2, OUT-OF-PROCESS

This blog demonstrates how to log to the database using semantic logging (SLAB) OUT-OF-PROCESS in a MVC4 application.

Follow the instructions as shown in part 1
Enterprise Library 6, Semantic Logging, Part 1, database listener

UPDATE: The service is now available as a NuGet package.

Download and install the OUT-OF-PROCESS service:
http://go.microsoft.com/fwlink/p/?LinkID=290903

Follow the instructions shown here:
http://entlib.codeplex.com/wikipage?title=Entlib6CTPReleaseNotes

Taken from the docs:

To use the out-of-proc SLAB service, follow these steps:

Create an event source class that defines your log messages by extending the EventSource class in the System.Diagnostics.Tracing namespace.

Add code to your application that generates log messages by invoking methods in your EventSource implementation.

If you want to collect and process log messages out-of-process, download and install the SemanticLogging-svc.exe Windows Service and edit the supplied configuration file (SemanticLogging-svc.xml) to define the event listeners. The block includes an XML schema file (SemanticLogging-svc.xsd) to support editing this configuration file in Visual Studio.

The download includes a PowerShell script, install-packages.ps1, that uses NuGet to download and install the dependencies of SemanticLogging-svc.exe in the current folder.

To install and run SemanticLogging-svc.exe as a Windows service, run SemanticLogging-svc.exe -start.

To install and run SemanticLogging-svc.exe as a console application, run SemanticLogging-svc.exe -console.

(Optionally) If you are using one of the database event listeners, run the supplied script to create a suitable database to store log messages.

NOTE: you can run your service as a console application or as a service.

Edit the following xml:
SLABoutOfProcess

Change the xml as follows:
SLABxmlConfig

The service is configured now to log BasicLogger events to the log file SemanticLogging-svc.runtime.log. Now we log out-of-process to the file and in process to the database.

Now we can log out of process to the database:

  <sqlDatabaseSink name="myDb" instanceName="OoPHomeController" connectionString="Data Source=.;Initial Catalog=Logging;Integrated Security=True">
		<sources>
        <!-- The below settings shows a simple configuration sample for the buit-in non-transient fault tracing -->
        <!-- Remove this eventSource if you'd like, and add your own configuration according to the documentation -->
        <!-- The name attribute is from the EventSource.Name Property -->
        <eventSource name="BasicLogger" level="LogAlways"/>
      </sources>
  </sqlDatabaseSink>

And here is the schema for the sql listener configuration.

 <xs:complexType name="SqlDatabaseSinkElement">
    <xs:complexContent mixed="false">
      <xs:extension base="SinkBase">
        <xs:attribute name="instanceName" type="NoEmptyString" use="required" />
        <xs:attribute name="connectionString" type="NoEmptyString" use="required" />
        <xs:attribute name="tableName" type="NoEmptyString" use="optional" />
        <xs:attribute name="bufferingIntervalInSeconds" type="PositiveAndMinusOneInteger" use="optional" />
        <xs:attribute name="bufferingCount" type="PositiveInteger" use="optional" />
        <xs:attribute name="maxBufferSize" type="PositiveInteger" use="optional" />
        <xs:attribute name="bufferingFlushAllTimeoutInSeconds" type="PositiveAndMinusOneInteger" use="optional" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

Source code:
https://github.com/damienbod/MVCEL6DbLogging.git

Here’s how it works:
ELoutOfProcessDiagram

Enterprise Library 6, Semantic Logging, Part 1, database listener
Enterprise Library 6, Semantic Logging, Part 3, Getting into the details
Enterprise Library 6, Semantic Logging, Part 4 advantages, customising

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: