Log4net Rolling File Appender Configuration

Posted By admin On 12/01/22
Active5 years, 11 months ago

I have a Log4Net RollingFileAppender that is configured as:

Looking at the documentation, the The default rolling style is Composite, so it makes sense this will roll when it reaches a certain size (the default of 10MB), not just on the date.

If the file cannot be opened for writing when a message is logged then the message will be discarded by this appender. When rolling a backup file necessitates deleting an older backup file the file to be deleted is moved to a temporary name before being deleted. CAUTION A maximum number of backup files when rolling on date/time boundaries is not supported. Namespace: log4net.Appender. Assembly: log4net (in log4net.dll) See Also.

Appender

The problem is when it hits the size, it is restarting the log and I am losing the data from the first half of the day (it reaches this size around noon).
Why wouldn't this just roll to a new file and all future log lines are put into the MyLog.log?Or is it the log is rolling, but then at midnight, it is rolling again and overwritting the dated log (eg. rolling to MyLog.log2009-04-08 once it reaches 10MB, and then overwritting this same file at midnight)?

I will set the

Is this all I have to do to ensure it only rolls on the Date boundary? Can I change this on the fly in the Log4Net.config, or do I have to restart the application? It is running on IIS6.

Philipp M
1,6897 gold badges25 silver badges37 bronze badges
Tai SquaredTai Squared
7,25323 gold badges69 silver badges79 bronze badges

2 Answers

Here's my settings. It rolls only on date:

Log4net Rolling File Appender Configuration

Changes to your web.config, will restart the application automatically (so you'll lose sessions, etc).

Philipp M
1,6897 gold badges25 silver badges37 bronze badges
dommer

Rollingfileappender Configuration

dommer
16.3k8 gold badges59 silver badges114 bronze badges

Try adding the maxSizeRollBackups parameter in your RollingFileAppender to solve half of our problem. This way, when the log file rolls, it won't overwrite your old log, but will roll it to another file.

Philipp M
1,6897 gold badges25 silver badges37 bronze badges
Rolling file cart

Log4net Rolling File Appender Configuration List

EddieEddie

Log4net Rollingstyle

47k19 gold badges112 silver badges139 bronze badges

Not the answer you're looking for? Browse other questions tagged logginglog4netrollingfileappender or ask your own question.