How to configure Semantic Logging

Topics: Logging Application Block, Semantic Logging Application Block
Mar 11, 2014 at 4:12 PM
Hi all,

I want to configure Semantic Logging by app.config but I don't know how.
I found this
but describe only how to use config file to configure SQL Server Sink with Semantic Logging Service, so in out-proc and not in in-proc.

I want o use
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns=""
               xsi:schemaLocation=" SemanticLogging-svc.xsd">
    <sqlDatabaseSink connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Logging;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
                     instanceName ="(localdb)\v11.0"
        <eventSource name="SqlApplicationEventSource" level="Informational"/>
to configure my in-proc by SqlDatabaseLog class and not use this code for my configuration
var eventListener = SqlDatabaseLog.CreateListener(
                @"Data Source=(localdb)\v11.0;Initial Catalog=Logging;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False");
How could I say to Semantic Logging to use the config file?

Thanks in advance
Luca Jonathan Panetta
Mar 12, 2014 at 12:52 AM
There is no out of the box declarative XML configuration for the Semantic Logging Block in-process. The preferred configuration is programmatic. See Configuring the Semantic Logging Application Block for more details.

Here's an example:
var listener1 = new ObservableEventListener();

  MyCompanyEventSource.Log, EventLevel.LogAlways, 
  MyCompanyEventSource.Keywords.Perf | MyCompanyEventSource.Keywords.Diagnostic);

The easiest way to add some control would be through app settings and have the application configuration itself appropriately. If you wanted full XML integration you could create a custom configuration section.

Randy Levy
Enterprise Library support engineer
Support How-to
Mar 25, 2014 at 10:07 AM
Hi Randy,

Forgive me if this has already been answered before, but what is the reasoning of the team to NOT enable xml config like other Entlib blocks do and even ENCOURAGE we to do the config programmatically which kind of contra the common wisdom?

Is that because the SLAB is still too new or the team is too busy on other important things?


Mar 26, 2014 at 12:29 PM
Programmatic vs. declarative (XML) configuration is a topic where you could probably dredge up a good argument (not quite at the level of tabs vs. spaces or bracket placement, though ;) ).

In my experience the trend these days is leaning towards programmatic configuration which is why the preferred configuration approach for Enterprise Library 6 is a "flexible programmatic approach". I think it was for that reason that there is no in-process configuration for the new Semantic Logging Application Block.

Randy Levy
Enterprise Library support engineer
Support How-to
Mar 26, 2014 at 3:33 PM
Hi, Randy,

Thanks again for updating me this, I've no idea at all that this is a trend now, would you mind to point me to somewhere showing this kind of heated debate? I really don't understand how will configuration-by-code could handle after-deployment-changes?


Mar 27, 2014 at 1:07 PM
This blog entry talks a bit about it: and you can see that in newer frameworks from Microsoft. For example, compare the configuration of ASP.NET MVC (smallish) to WCF (massive).

Also, what I was thinking of in addition to straight programmatic configuration is the popularity of convention over configuration: .

One way to view the lack of configuration is that there is no complicated, error prone configuration required.

You should be able to do some in-process reconfiguration based on an event. Where you thinking of monitoring a file to change the logging level?

Randy Levy
Enterprise Library support engineer
Support How-to