如果每个时间跨度发生/发生超过 N 次,我如何设置 log4net 来记录某些事件?
基本上,我希望能够在我的应用程序中记录诸如“HTTP 超时”之类的事件,前提是这些事件每分钟发生超过 100 次(例如)。
有没有办法配置 log4net 来处理这样的任务?
提前致谢,
Basically, I would like to be able to log events such as "HTTP timeouts" in my application only if they happen more than 100 times per minute (for example).
Is there any way to configure log4net to handle such a task?
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您不能将其配置为那样运行。
但是,您可以通过编写自己的自定义 Appender 来相当轻松地实现这一点。只需从
AppenderSkeleton
继承,并使用您自己的逻辑覆盖Append
方法(根据需要将事件参数传递给基本实现)。log4net 可以从配置文件中自动加载类中的任何公共属性,因此您也可以通过这种方式指定阈值速率。
No, you cannot configure it to behave that way.
But, you can achieve this fairly easily by writing your own, custom Appender. Simply inherit from
AppenderSkeleton
, and override theAppend
method with your own logic (passing the event parameter to the base implementation as needed).Any public property in your class can will be automatically loaded by log4net from the configuration file, so you can also specify the threshold rate this way.
这看起来像是您可能感兴趣的内容。
log4net - 任何过滤器仅记录第 N 条消息?
或以下是限制电子邮件的示例:
http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200805.mbox/%3C6D3CA9B0BEA31640B4E6338360C84740023C49C1@entdc1ms02.corp.gomez.com%3E
This looks like something you may be interested in.
log4net - any filter for logging only the Nth message?
or here's an example of throttling emails:
http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200805.mbox/%3C6D3CA9B0BEA31640B4E6338360C84740023C49C1@entdc1ms02.corp.gomez.com%3E