开发者

Do you know of a log4net appender which rolls on date, but let's you limit the total number of files?

I need to define an appender for log4net in a way that I get one log file for each day, but the total number of files ar开发者_运维百科e limited to, let's say, 30. That is I want to keep only the logs not older then 30 days, delete the older ones.

I've tried doing it with RollingFileAppender, but it seems that specifying a limit of files to keep is not supported. Do you know of an alternative solution that I could use?


I spent some time looking into this a few months ago. v1.2.10 doesn't support deleting older log files based on rolling by date. It is on the task list for the next release. I took the source code and added the functionality myself, and posted it for others if they are interested. The issue and the patch can be found at https://issues.apache.org/jira/browse/LOG4NET-27 .


Write a C# WinService or make in your application a BackgroundWorker that will monitor once a day your old log files and delete it. You can use the FileSystemWatcher for this scope.

Or just test at each application running the presence of new log files and delete it.

An other option will be do not store files locally but send it via network (mail, distant server etc).

See also duplicate questions: here and here.


can you use the 'Composite' log type? more here: http://logging.apache.org/log4net/release/config-examples.html

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜