You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Lee Chun Kit <ch...@gmail.com> on 2011/04/04 11:54:14 UTC

RollingFileAppender does not seem to preserve old log messages

Here is the configuration xml I am using:
<log4net debug="true">
    <appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
        <lockingModel type="log4net.Appender.FileAppender+ExclusiveLock" />
        <file value="./output/" />
        <appendToFile value="true" />
        <rollingStyle value="Composite" />
        <datePattern value="'LoggerTest'yyyyMMdd'.log'" />
        <maxSizeRollBackups value="-1" />
        <maximumFileSize value="10MB" />
        <staticLogFileName value="false" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%level] %message%newline" />
        </layout>
    </appender>
    <logger name="Logger" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="RollingLogFileAppender" />
    </logger>
</log4net>
---
Here are the significant portions of my code:

    static readonly string superLongText = new string('a', 1024);
    static readonly log4net.ILog log = log4net.LogManager.GetLogger("Logger");

    static void Main(string[] args)
    {
        log4net.Config.XmlConfigurator.Configure("./TestConfig.xml")));
        	
        for (int i = 0; i < 1000; i++)
        {
            log.Debug("" + i + " " + superLongText);
        }
    }
---
Total size (in bytes) of the generated logs after each execution of my program:
01: 1061890
02: 2123780
03: 3185670
04: 4247560
05: 5309450
06: 6371340
07: 7433230
08: 8495120
09: 9557010
10: 10618900
11: 11680790
12: 12742680
13: 13804570
14: 14866460
15: 15928350
16: 16990240
17: 18052130
18: 19114020
19: 20175910
20: 10751650
---
log files:
  LoggerTest20110404.log
  LoggerTest20110404.log.1
---
After run 19, LoggerTest20110404.log is 9463KB (almost 10MB), and
LoggerTest20110404.log.1 is 10241KB.
After run 20, LoggerTest20110404.log is 260KB, and
LoggerTest20110404.log.1 is 10241KB. However, file
LoggerTest20110404.log.2 is not created (I expect the logger to do
so).

Does anyone know why is it the case that the log information is not
preserved between run 19 and run 20? May I know if it is an error in
my xml configuration or a limitation of the RollingFileAppender and
the combination of settings I used?

Thanks.

Regards,
Chun Kit