3

From the log4net documentation:

Following example show how to configure the RollingFileAppender to roll log files on a date period and within a date period on file size. For each day only the last 10 files of 1MB will be kept.

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logfile" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>

So, if the logging has been done for 30 days, it will keep the last 10 files for each day.

But, I need to keep the log files for the last 20 days only. Any other log file older than 20 days needs to be deleted.

Any help is appreciated.

CodeZila
  • 919
  • 2
  • 14
  • 31
  • What tells you that the log files are kept for 30 days? You probably want to look at this answer: https://stackoverflow.com/a/97641/2137237 – Markus Deibel Mar 21 '18 at 10:52
  • Try following this thread: https://stackoverflow.com/questions/95286/log4net-set-max-backup-files-on-rollingfileappender-with-rolling-date – Sameh May 20 '20 at 14:38

0 Answers0