问题描述
我在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="..\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>
我只希望保留日志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?
感谢你在前进。
推荐答案
下面就是从这里另外一个问题上,以便要求基本相同的事情: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的源$ C $ C库实现的,但一直没有被释放。另外海报显示,他使用清理旧文件中的某些code定期。
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的删除日志文件自动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!