How to configure Semantic Logging

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

I want to configure Semantic Logging by app.config but I don't know how.
I found this http://www.shujaat.net/2013/09/entlib6-semantic-logging-with-sql.html
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="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw SemanticLogging-svc.xsd">
  
  <traceEventService/>
 
  <sinks>
    <sqlDatabaseSink connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Logging;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
                     instanceName ="(localdb)\v11.0"
                     name="sqlServerEventSink">
      <sources>
        <eventSource name="SqlApplicationEventSource" level="Informational"/>
      </sources>
  </sqlDatabaseSink>
  </sinks>
</configuration>
to configure my in-proc by SqlDatabaseLog class and not use this code for my configuration
var eventListener = SqlDatabaseLog.CreateListener(
                @"(localdb)\v11.0",
                @"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
Editor
Mar 12 at 1: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();

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

listener1.LogToFlatFile("MyLogFile.log");
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
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Mar 25 at 11: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?

Best,

Dong
Editor
Mar 26 at 1: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
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Mar 26 at 4: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?

Best,

Dong
Editor
Mar 27 at 2:07 PM
This blog entry talks a bit about it: http://blog.urth.org/2011/01/06/config-versus-code/ 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: https://en.wikipedia.org/wiki/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
entlib.support@live.com
Enterprise Library support engineer
Support How-to