Using and initializing the SLAB in WCF service

Topics: Semantic Logging Application Block
Oct 21, 2013 at 6:02 PM
Edited Oct 21, 2013 at 6:05 PM
We are planning to use SLAB for logging in our WCF service. The services are by default configured to be "PerSession" InstancecontextMode based. It has 4 different operations. I've a code like the following to initialize the listeners
        var listener = new ObservableEventListener();
        listener.EnableEvents(eventSource, eventLevel, keywords);
My question is:
  • What is the correct place to write a code that initializes my SLAB objects.
  • I would like the initialization to be done only once (regardless of the instancecontext setup), so that all subsequent client instances can "skip" the initializer, but the service should be able to use the "listener" instance created already
  • And whats the correct place to "cleanup" or "dispose" my listener objects (and that should also be done only once probably when the IIS / or AppPool is recycled)
  • Can the "ObservableEventListener" variable be declared as "static"?
[Edit: I want to use the Out-of-process setup for this]

Thanks in advance for any help / insight on this.
Oct 21, 2013 at 6:48 PM
If you wish to use the out of process listener then you do not need to perform any setup of listeners in your application. When configured, the out of process ETW listener will pick up the events. Just call the appropriate EventSource method in your application and the events should be logged by the out of process service!

For an in-process scenario, in general you would initialize listeners at bootstrap time and dispose at shutdown (if this is in IIS then Application_Start/Application_End would make sense).

Randy Levy
Enterprise Library support engineer
Support How-to
Oct 21, 2013 at 7:47 PM
Thanks Randy for the quick response. This clears up my problem. I didn't see anywhere in the documentation about listener code being not needed in the out of process scenario. May be I overlooked.
  • Can you point to the right section on the document. (and any workinge sample for "SQLDB" based OOP logging).
  • Is there a best practice way to identify ETW log-able events in the application.
Oct 21, 2013 at 8:19 PM
You can read about out-of-process logging using the Semantic Logging Application Block in the Developer’s Guide to Microsoft Enterprise Library (2nd edition). There are a variety of references throughout Chapter 6. The section "How do I Use the Semantic Logging Application Block to Log Events Out-ofProcess?" is very applicable and includes sample configuration for a sqlDatabaseSink.

In terms of what to log, that could be dependent on functional or non-functional requirements and, in the absence of those, is usually based on what information might be useful to know.

Randy Levy
Enterprise Library support engineer
Support How-to