2008年5月28日 星期三

C# Common.Logging Configuration

Logging mechanism is very important for service program. The log information is only data source to know what happen in the application especially in service like program.
Common.Logging is well integrated with Spring.NET framework, however, the configuration of the Common.Logging is really not pleasant experience. Two reasons make this configuration so difficult. The First is the version of the logging component is really confuse people. Second, forget the external configuration should be copied to output directory.
Be aware the logging components' version.

Common.Logging.dll 1.2.0.0
Common.Logging.Log4Net.dll 1.2.0.2
Common.Logging.NLog.dll 1.2.0.2
log4net.dll 1.2.10.0
NLog.dll 1.0.0.505

Here is the setting in App.config


<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net">
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~/log4net.config"/>
</factoryAdapter>
</logging>
</common>

log4net.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="log.txt" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>

<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</root>

</log4net>
</configuration>




沒有留言: