Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net RollingFileAppender spewing tons of logs, maxSizeRollBackups has no effect

A service I have is suddenly spewing tons of log files and is not limiting the number of files written. The logs are (sort of) named MyService.2015-01-08.1, MyService.2015-01-08.2, MyService.2015-01-08.3, etc, all the way until 218 currently. I'd like to limit this to 10 per day instead of it being unlimited like right now. Here is what the log config was previously:

<appender name="RollingFileAppender" type="Ourlib.Logging.CustomRollingFileAppender">
  <file value="c:\logs\myservice" />
  <appendToFile value="true" />
  <rollingStyle value="Composite" />
  <staticLogFileName value="false" />
  <maxSizeRollBackups value="-1" />
  <countDirection value="1" />
  <maximumFileSize value="5000KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%utcdate [%thread] %-5level %property{CorrelationId} %property{CallPath} %logger{2} - %message%newline" />
  </layout>
</appender>

I've made some changes, seen below. Notably, I've set maxSizeRollBackups to 10, which I thought would fix the problem, but doesn't seem to have made a difference.

<appender name="RollingFileAppender" type="Ourlib.Logging.CustomRollingFileAppender">
  <file value="c:\logs\myservice" />
  <appendToFile value="true" />
  <rollingStyle value="Composite" />
  <staticLogFileName value="false" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="5000KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%utcdate [%thread] %-5level %property{CorrelationId} %property{CallPath} %logger{2} - %message%newline" />
   </layout>
</appender>

The change has been deployed but it's still creating new log files, way past the newly set 10.

Assuming that my deploy was done correctly, what could be wrong? Am I misunderstanding the config properties I changed, or is there something else going on here?

Thanks all!

like image 324
Seventh Helix Avatar asked Jan 09 '15 03:01

Seventh Helix


1 Answers

Try adding DatePattern and keep your change of maxSizeRollBackups value as 10 like this

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
     <file value="c:\logs\myservice" />
     <appendToFile value="true" />
     <rollingStyle value="Composite" />
     <datePattern value=".yyyy-MM-dd" />
     <maxSizeRollBackups value="10" />
     <maximumFileSize value="5000KB" />
     <countDirection value="1"/>
     <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
     </layout>
</appender>

This is a Composite RollingFileAppender which keeps max of 10 5000KB log backups per day

like image 127
display name Avatar answered Nov 21 '22 11:11

display name