Reputation: 1017
I have a process that loops through 100,000+ items and writes extensively in a log about them, and I'm having trouble at keeping all the logs that I need since log4net isn't working how I expect it to.
My config looks like this:
<appender name="debug" type="log4net.Appender.RollingFileAppender">
<file value="logs\" />
<datePattern value="yyyyMMdd'_DEBUG.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline[%date]-%level-%logger[%M]- Linea:%L - %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="debug"/>
<param name="LevelMax" value="debug"/>
</filter>
</appender>
With that setup, I expect that as soon as the first file is full, a second file is created, and then a third, etc, with a maximum of 10 for each day. I assume that the only way to overwrite any previous log would be having 10 full files, and the next entries would have to rewrite existing ones from the first. However, what's happening is that I'm having a file created after the first one is full (and turned into the 1st backup), but after the second file is full, instead of turning it into another backup and going for a third file, it start overwriting the original file.
So I end up with
20171005_DEBUG.log
20171005_DEBUG.log.1
and nothing else, with 20171005_DEBUG.log being the one getting overwritten.
I can "fix" this by changing the maximum file size to 100MB or anything really huge, but I'd rather know what am I doing wrong here. Anybody?
Upvotes: 1
Views: 738
Reputation: 18061
Changing your
<rollingStyle value="Composite" />
to either
<rollingStyle value="Date" />
or
<rollingStyle value="Size" />
should give you the desired behavior.
Composite
considers both, Date and Size.
See RollingFileAppender.RollingModes
Since you stated dealing with 100.000+ lines of log, have you considered logging to a database instead?
Upvotes: 3