您是否知道 log4net 附加程序可以按日期滚动,但可以限制文件总数?
我需要为 log4net 定义一个附加程序,每天获取一个日志文件,但文件总数限制为 30 个。也就是说,我只想保留不超过 30 天的日志,删除旧的。
我尝试过使用 RollingFileAppender 来完成此操作,但似乎 不支持指定要保留的文件限制。您知道我可以使用的替代解决方案吗?
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 are 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
几个月前我花了一些时间研究这个问题。 v1.2.10 不支持根据日期滚动删除较旧的日志文件。它在下一个版本的任务列表中。我自己获取了源代码并添加了功能,如果其他人感兴趣的话,可以将其发布给他们。该问题和补丁可以在 https://issues.apache.org/jira 找到/browse/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 .
编写一个 C# WinService 或在您的应用程序中创建一个 BackgroundWorker,它将每天监视一次您的旧日志文件并将其删除。您可以为此范围使用 FileSystemWatcher。
或者只是测试每个运行的应用程序是否存在新日志文件并将其删除。
另一种选择是不在本地存储文件,而是通过网络(邮件、远程服务器等)发送文件。
另请参阅重复的问题:此处 和此处。
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.
您可以使用“复合”日志类型吗?更多信息: http://logging.apache.org/log4net/release/config -examples.html
can you use the 'Composite' log type? more here: http://logging.apache.org/log4net/release/config-examples.html