Hello,
I am using log4net for a couple years, but it still have some secrets...
I'm using RollingFileAppender in my app and I'd like to limit number of
stored log files - I wan't to keep logs for the last 10 days, any older
log should be deleted.
First idea was to call once a day simple procedure, which finds all log
files according its name and deletes all, which _creation_ date is older
than 10 day. But it didn't work - first 10 day id nothing deleted what
is OK, but then all files are deleted as all rolled files have the same
creation date.
So I am wondering how file rolling really works? I expected that old
file is reanmed and new file is created, but it isn't probably true.

Second idea is to delete old logs by other way - according documentation
MaxsizeRollBackups may help. Has anybody experience with this settings?
Of course I can try myself, but I need result today, I can not wait for
10 days :-(
Or is there any other way how to preserve only last 10 logfiles?

My config file:
<log4net>
        <appender name="Console"
type="log4net.Appender.ConsoleAppender">
                <layout type="log4net.Layout.PatternLayout">
                        <!-- Pattern to output the caller's file name
and line number -->
                        <conversionPattern value="%date{HH:mm:ss,fff}
%5level [%thread] %message%n" />
                </layout>
                <Threshold value="DEBUG" />
        </appender>

        <appender name="RollingFile"
type="log4net.Appender.RollingFileAppender">
                <appendToFile value="true" />
                <file value="Log/Service.log" />
                <layout type="log4net.Layout.PatternLayout">
                        <conversionPattern value="%date{HH:mm:ss,fff}
%5level [%2thread] %message (%logger{1}:%line)%n" />
                        <!--<conversionPattern
value="%date{HH:mm:ss,fff} %5level %message (%type{1}:%line)%n" />-->
                </layout>
                <rollingStyle value="Date" />
                <Threshold value="DEBUG" />
        </appender>

        <root>
                <level value="DEBUG" />
                <appender-ref ref="Console" />
                <appender-ref ref="RollingFile" />
        </root>
</log4net>

With regards
Radovan Raszka

Reply via email to