More structured logging/tracing in SharpMap

Topics: SharpMap v0.9 / v1.x
Coordinator
May 23, 2012 at 7:46 AM
Edited May 24, 2012 at 7:25 AM

Hi all,

I've updated the trunk with code that replaces the logging to Console, Debug, Trace with logging to Common.Logging (http://netcommon.sourceforge.net/index.html) instead.

This way it's possible to control what gets logged even in production environments and not just by compilation flags.

If you check the app.config for the WinFormsSamples. It's configured to log all messages to Console. 

There is also an example in that app.config on how to instead log to log4net for those of you that are using that.

Applications that does not want debug/log messages output don't need to do anything in their config file and all messages will just be suppressed.

The SharpMap documentation will be updated with information about how to trace/log sharpmap. Until then, here's an example

Log to Console
Add this to config file

<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
 </sectionGroup>
</configSections>
<common>
    <logging>
      <!--Log to Console_-->
      <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
        <arg key="level" value="DEBUG" />
        <arg key="showLogName" value="true" />
        <arg key="showDataTime" value="true" />
        <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
      </factoryAdapter>
    </logging>
  </common>

Log to log4Net

Add this to config file 

 <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
    <section name="log4net"
           type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>

 

<common>
    <logging>
      <!-- Log with Log4Net -->
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </common>
<!-- configures log4net to write into a local file called "log.txt" -->
  <log4net>
    <appender name="MainAppender" type="log4net.Appender.FileAppender">
      <param name="File" value="log.txt" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="MainAppender" />
    </root>
  </log4net>
May 24, 2012 at 4:24 AM

THanks.