I am using log4net RollingFileAppender in a windows service program written in C#. The number and size of files in logs directory is growing too fast, need cleanup. The configuration is below:
<appender name="Rolling Log" type="log4net.Appender.RollingFileAppender">
<file value="..\logs\MyProgram.%cs{instanceName}.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value=".yyyy-MM-dd.lo\g" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="150MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%-5level] %property{remoteUser} [%threadIdentity] %type{1}.%method - %message%newline%exception" />
</layout>
I only want to keep 30 days of logs. How can I configure log4net to delete the logs automatically? If not available through log4net, what solutions would I have?
Thank you in advance.
The log4net. config file is located in the \Enterprise7\bin\ directory and is the configuration file for the log4net logging application.
Gets or sets the maximum number of backup files that are kept before the oldest is erased.
Log4net provides a simple mechanism for logging information to a variety of sources. Information is logged via one or more loggers. These loggers provide 5 levels of logging: Debug.
Here is another question from here on SO that asks essentially the same thing: Log4Net: set Max backup files on RollingFileAppender with rolling Date
The consensus was that log4net does not support it directly. One poster says that it has been implemented in log4net's source code repository, but has not been released yet. Another poster shows some code that he uses to cleanup old files periodically.
I'm pretty sure that you can't do with the existing appender, although I can't confirm it.
However, I see two options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With