log4net-删除按日期滚动的旧文件 [英] log4net - Remove old files rolling by date

查看:203
本文介绍了log4net-删除按日期滚动的旧文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

意图:

a)我希望我的日志按日期以以下文件格式yyyy-MM-dd.txt滚动.

a) I want my logs to be rolled by date in following file format yyyy-MM-dd.txt.

b)除此之外,我还要删除超出maxSizeRollBackups范围的旧文件.

b) Additionally to this I want to remove old files which are out of maxSizeRollBackups range.

CAUTION A maximum number of backup files when rolling on date/time 
  boundaries is not supported. [RollingFileAppender spec][1]

解决方案

对于a)足以进行配置

<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="logs\" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="30" />
  <datePattern value="yyyy-MM-dd'.txt'" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.XmlLayoutSchemaLog4j"/>
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>

对于b) 从RollingFileAppender +删除内容的继承是实现此目的的唯一方法吗?

for b) Is the inheritance from RollingFileAppender + delete stuff the only way to achieve this ?

推荐答案

几个月前,我花了一些时间研究这个问题. v1.2.10不支持根据日期滚动删除较旧的日志文件.它在下一个版本的任务列表中.我获取了源代码,并自己添加了功能,如果有兴趣,可以将其发布给其他人.该问题和补丁可以在 https://issues.apache.org/jira/中找到浏览/LOG4NET-27 .

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 .

这篇关于log4net-删除按日期滚动的旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆