Log4net - delete any logs that is over 14 days old [duplicate]

℡╲_俬逩灬. 提交于 2019-12-11 03:53:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!