log4net Overwrite my log file when start next day

1.7k views Asked by At

I have a problem with log4net in this scenario

  1. Today is 30/11/2014
  2. Current log file is called log.txt
  3. Log file builds up throughout the day.
  4. Next day (01/12/2014) , log file exist at log.txt20141130
  5. But when I Open log file, all entries from 30/11 are lose, log only contains a very small number of entries dated 01/12/2014 just after midnight.

Now I'm now losing my logs for each day as they are being overwritten by the first few logs after midnight.

Is there any way I can prevent this from happening?

Thankyou

This is my Config log4net file

   <appender name="Test" type="log4net.Appender.RollingFileAppender">
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <file value= "C:\Test\Log\log.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Composite" />
    <datePattern value="yyyyMMdd" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%date|%level|%thread|%property{function}|%property{flowid}|%message%newline" />
    </layout>
  </appender>
2

There are 2 answers

1
antinutrino On
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value=".\\Log\\log.txt" />
  <appendToFile value="true" />
  <maximumFileSize value="10MB" />
  <maxSizeRollBackups value="2" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date:%level %thread %logger - %message%newline" />
  </layout>
</appender>

Have you tried removing <rollingStyle value="Composite" />

Above is my log4net configuration and it rolls the files as expected, previous days logs all available.

0
VsMaX On

I've had the same problem, it looks like a bug within log4net.

I ended up with

<staticLogFileName value="false" />
<datePattern value=".yyyyMMdd" />

So I don't have now generic log.txt file, log4net logs directly to files with date stamps in the name, but at least it works fine with logging around midnight.