JoeRod
JoeRod

Reputation: 51

RollingFileAppender, after it rolls, it doesnt append anymore

I have a rolling file appender and every night it rolls the file. However, when it rolls it, the new file only has one log entry. It seems that file is not appending log entries anymore. If I restart the service it logs correctly.

Here are my settings:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Log.txt"/>
  <appendToFile value="true" />
    <staticLogFileName value="true" />
  <rollingStyle value="Date" />
  <datePattern value=" yyyy-MM-dd" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <threshold value="DEBUG" />
  <layout type="log4net.Layout.PatternLayout">
   <conversionPattern value="%date [%thread] %-5level %logger  - %message%newline" />
  </layout>
 </appender>

Upvotes: 2

Views: 3949

Answers (2)

Mitch Wheat
Mitch Wheat

Reputation: 300529

Set maxSizeRollBackups to a value perhaps (maxSizeRollBackups set to negative 1 to allow an infinite number of backup files)

This example show how to configure the RollingFileAppender to roll log files once per program execution. The appendToFile property is set to false to prevent the appender from overwriting the existing files. The maxSizeRollBackups is set to negative 1 to allow an infinite number of backup files. The file size does have to be limited but here it is set to 50 Gigabytes which, if a log file exceeds this size limit during a single run then it will also be rolled.

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="logfile.txt" />
    <appendToFile value="false" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="-1" />
    <maximumFileSize value="50GB" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

Ref.

Upvotes: 0

JoeRod
JoeRod

Reputation: 51

I found what the issue was. I removed this line in the configuration and it started to append correctly after it rolled the file:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> 

Upvotes: 3

Related Questions