views:

31

answers:

1

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

Unfortunately this means that, out of the box, this doesn't include being able to set the boundary to be a week number. There are ways of getting this value in C#, but it's not obvious that we can extend the SimpleDateFormatter or provide a different implementation of IDateFormatter and use that instead (or even in a custom RollingFileAppender).

So how might we get a Log4Net RollingFileAppender to roll weekly?

A: 

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.

Stefan Egli