Luis
Luis

Reputation: 1880

Example of using a TraceSource with Common.Logging

I've read this question and I know its possible: Common.Logging for TraceSource

Can someone please post an example. Also it could be helpfull if it can be configured to use the TraceSource in code instead of using the .config file.

Thanks

Upvotes: 0

Views: 1143

Answers (1)

Daniel Blankensteiner
Daniel Blankensteiner

Reputation: 76

If your goal is to have Common.Logging forward messages to a TraceSource, then your logger name and tracesource name have to match.

<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
        <arg key="level" value="ALL" />
        <arg key="showLogName" value="true" />
        <arg key="showDataTime" value="true" />
        <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
        <arg key="useTraceSource" value="true" />
      </factoryAdapter>
    </logging>
  </common>
  <system.diagnostics>
    <sources>
      <source name="SomeSourceName" switchName="YourSwitch">
        <listeners>
          <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="Application"/>
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="YourSwitch" value="Information"/>
    </switches>
  </system.diagnostics>
</configuration>

And from code you write:

var logger = Common.Logging.LogManager.GetLogger("SomeSourceName");

Hope this helps even though the post is 2 months old and the tracesouce is setup via .config.

Upvotes: 3

Related Questions