Have a Log4Net RollingFileAppender set to roll weekly

前端 未结 3 1848
感动是毒
感动是毒 2020-12-11 07:23

The DatePattern string needs to be something that the SimpleDateFormatter will accept.

Unfortunately this means that, out of the box, this

3条回答
  •  孤街浪徒
    2020-12-11 07:40

    It is not that simple. The RollingFileAppender uses DateTime.ToString() to determine the "roll point". The statement of the log4net help ist not wrong since the SimpleDateFormatter uses this method as well but it is somewhat misleading: You cannot inject a different date formatter to make the rolling file appender work the way you want.

    If you really need roll by week feature then the easiest way would be to derive from the RollingFileAppender and override the AdjustFileBeforeAppend() method. Did not test this, but that should do the trick.

提交回复
热议问题