March 6, 2008

Setting up Log4Net in the application config file.

Setting up log4net to use a rolling file appender and a trace appender
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net"
 type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net debug="false">
    <appender name="RollingFileAppender"
 type="log4net.Appender.RollingFileAppender">
      <file
 value="${ENVIROMENTALVARIABLENAME}\\MyApplicationName.exe.txt" />
      <appendToFile value="true" />
      <maximumFileSize value="100KB" />
      <maxSizeRollBackups value="5" />
      <param name="RollingStyle" value="Size" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] -
 %m%n" />
      </layout>
    </appender>
    <appender name="TraceAppender"
 type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <root>
      <priority value="ALL" />
      <appender-ref ref="RollingFileAppender" />
      <appender-ref ref="TraceAppender" />
    </root>
  </log4net>
</configuration>

No comments: