George Mauer
George Mauer

Reputation: 122092

How to get log4net to keep only the last X days of logs?

I only want log4net to keep let's say 10 days-worth of log files as keeping them growing indefinitely will eventually eat up my disk space. I had thought that I could do this by setting

<maxSizeRollBackups value="10" />

on my RollingFileAppender but no dice. How do I do this?

Upvotes: 7

Views: 13243

Answers (2)

Sanjay Sheth
Sanjay Sheth

Reputation: 1619

Take a look at this similar post for answers.

Make sure you are not rolling the logs by Date as per the SDK:

A maximum number of backup files when rolling on date/time boundaries is not supported.

Upvotes: 11

Sml004
Sml004

Reputation: 513

This is what exactly I am looking for.

Maybe this will help?

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logfile" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="10" />
<layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>

Upvotes: -1

Related Questions