本文介绍了Log4Net 可以自动删除日志文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用 C# 编写的 Windows 服务程序中使用 log4net RollingFileAppender.日志目录中文件的数量和大小增长过快,需要清理.配置如下:

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="..logsMyProgram.%cs{instanceName}.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value=".yyyy-MM-dd.log" />
<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>

我只想保留 30 天的日志.如何配置 log4net 以自动删除日志?如果不能通过 log4net 获得,我有什么解决方案?

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?

提前致谢.

推荐答案

这里是 SO 上的另一个问题,它基本上问了同样的问题:Log4Net:使用滚动日期在 RollingFileAppender 上设置最大备份文件

Here is another question from here on SO that asks essentially the same thing:Log4Net: set Max backup files on RollingFileAppender with rolling Date

共识是 log4net 不直接支持它.一张海报说它已在 log4net 的源代码存储库中实现,但尚未发布.另一张海报展示了他用来定期清理旧文件的一些代码.

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.

这篇关于Log4Net 可以自动删除日志文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:50