log4net: log information into different log files

Posted by Daoming Yang on Stack Overflow See other posts from Stack Overflow or by Daoming Yang
Published on 2010-03-08T23:17:48Z Indexed on 2010/03/08 23:21 UTC
Read the original article Hit count: 358

Filed under:

I have the following configurations in my web.config file, but how can I log the information into data.txt and general.txt separately in C#?

Could anyone provide some sample code for me?

<appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
  <file value="App_Data/Logs/general.txt" />
  <appendToFile value="true" />
  <maximumFileSize value="2MB" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="5" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
  </layout>
</appender>
<appender name="DataLog" type="log4net.Appender.RollingFileAppender">
  <file value="App_Data/Logs/data.txt" />
  <appendToFile value="true" />
  <maximumFileSize value="2MB" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="5" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
  </layout>
</appender>

© Stack Overflow or respective owner

Related posts about log4net