Search code examples
log4net

why files not delete for maxDateRollBackups settings


I have below log4Net configuration,

<appender name="WhateverYouNameThis" type="log4net.Appender.RollingFileAppender">
    <threshold value="All" />
    <file value="logs\WhateverYouNameThisFile.log" />
    <appendToFile value="true" />
    <maxDateRollBackups value="2" />
    <maxSizeRollBackups value="2" />
    <maximumFileSize value="2KB" />
    <rollingStyle value="Composite" />
    <staticLogFileName value="true" />
    <datePattern value="yyyyMMdd-HH.lo\g" />
    <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p - %m%n" />
    </layout>
 </appender>

"maxSizeRollBackups =2" works fine. When file gets larger than 2KB, it will roll to another file, up to 2 times, and then these will start getting deleted too if it goes over 2 files.

but "maxDateRollBackups=2" is not working. Any files older than 2 days is not deleted. Please suggest the reason!

When date change the file rename with 1 day before date, but files older than 2 days is not delete,

enter image description here


Solution

  • This issue seems known in log4net. These issues https://issues.apache.org/jira/browse/LOG4NET-27 / https://issues.apache.org/jira/browse/LOG4NET-367 describes the major problems with the rolling file appender. If you have any new information, I am interested in solutions as well.