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:

Follow the instructions shown here:

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:

Change the xml as follows:

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">
        <!-- 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"/>

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" />

Source code:

Here’s how it works:

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: