简体   繁体   English

如何检测在 log4net 上滚动的跟踪文件

[英]How to detect trace file rolling on log4net

I am using C# 4.6.1.我正在使用 C# 4.6.1。

Let's assume I have successfully configured a log4net.Appender.RollingFileAppender, which will roll to a new trace file after a certain time or when the trace reaches a certain size threshold.假设我已经成功配置了一个 log4net.Appender.RollingFileAppender,它将在一段时间后或当跟踪达到特定大小阈值时滚动到新的跟踪文件。

What I want to do now is to detect every time there is a file roll, because I need to do a certain operation with the full trace file that was just rolled, which is out of the scope of the question (I basically need to zip it, copy it to a certain folder and raise an event).我现在要做的是每次有文件滚动时检测,因为我需要对刚刚滚动的完整跟踪文件进行某种操作,这超出了问题的范围(我基本上需要压缩它,将其复制到某个文件夹并引发事件)。

Is there a way to configure log4net to raise an event or execute a specific method when it is rolling to a new trace file?有没有办法将 log4net 配置为在滚动到新跟踪文件时引发事件或执行特定方法?

The log4net framework does not have out-of-the-box support for that or any configuration you can tweak to get it. log4net 框架没有开箱即用的支持,或者您可以调整以获得它的任何配置。

You need to implement your own custom appender class that inherits from RollingFileAppender and override its methods to suite your needs.您需要实现自己的自定义 appender 类,该类继承自RollingFileAppender并覆盖其方法以满足您的需求。 The methods that more likely be of your interest are Append , DoAppend , RollFile and the RollOver... methods.您更可能感兴趣的方法是AppendDoAppendRollFileRollOver...方法。

For more info check the reference .有关更多信息,请查看参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM