2

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>
0

2 Answers 2

3

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" /> 
1
  • What line did you remove from the configuration file? It doesn't look like it made it into your post.
    – wageoghe
    Commented Sep 13, 2010 at 18:44
0

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.

1
  • That answer didnt work. I enabled log4net logging and saw this log when it rolled the file: Opening file for writing [C:\GBI\Trunk\ExternalInterfaces\GBI.ExternalInterface.BACMLFIXWindowsService\bin\Debug\Log.txt] append [False]. So, the append property was set to false. Why is this happening???
    – JoeRod
    Commented Sep 7, 2010 at 13:45

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