3

I am creating a logger by using log4net's RollingFileAppender. One feature that I need to provide is to delete any logs that is over 14 days old.

How is that possible with using log4net's RollingFileAppender?

Thanks.

DanCode
  • 525
  • 3
  • 7
  • 25

1 Answers1

-3

Try this

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
  <file value=".\Logs\" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <staticLogFileName value="false" />
  <rollingStyle value="Date" />
  <datePattern value="'On_'yyyy-MM-dd'.log'" />
  <appendToFile value="true" />
  <maxSizeRollBackups value="14" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
  </layout>
</appender>
BhavO
  • 2,406
  • 1
  • 11
  • 13
  • So what it does is create the backup file with the name `"'On_'yyyy-MM-dd'.log'"`, but still uses roll backups? (since `maxSizeRollBackups` is set to 14). If this is the case, it might be also good to add `` to customize the size of each roll backup. – Xavier Peña Jul 17 '15 at 19:36
  • I need to roll a backup for every session. Hence, the rollingStyle value must be set to "Once". – DanCode Jul 17 '15 at 19:42