问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/31483089/log4net-delete-any-logs-that-is-over-14-days-old