-1

I want to create a log file using Log4Net. It should have daily activities log till midnight and resets for the next day. What appender to use and how?

EDIT: I forgot to mention, it should not create a different file each day but only one file.

sysboard
  • 287
  • 7
  • 19

1 Answers1

1

Something like this ?

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
  <file value="logs\" />
  <datePattern value="dd.MM.yyyy'.log'" />
  <staticLogFileName value="false" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="50MB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  </layout>
</appender>

It should do what you expect. I've included all settings to help you to tweak it to reach your final needs. There are many samples like this one on the web with explanations.

AFract
  • 8,868
  • 6
  • 48
  • 70