log4net 模式和级别过滤器
我想通过由(阈值和模式)组成的过滤器来过滤我的 log4net 输出。因此,我希望仅当日志级别为“ERROR”(或更高)时才允许使用模式“x”的日志,并且仅当日志级别为“INFO”(或更高)时才允许使用模式“y”的日志。我可以在一个附加程序中执行此操作,还是需要两个附加程序,每个附加程序都有自己的模式过滤器和阈值?
I would like to filter my log4net output by filters comprised of (threshold AND pattern). So I want to allow logs with pattern "x" only if they are level "ERROR" (or higher), and allow logs with pattern "y" only if they are level "INFO" (or higher). Can I do this in one appender, or do I need two appenders, each with its own pattern filter and threshold?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Log4net 允许您链接过滤器,但这仅适用于“OR”。我认为你也可以让它做“AND”操作,但不是你真正想要的。我会编写自己的过滤器来检查级别和模式是否匹配。然后链接此过滤器的两个实例以使其检查第一个条件和第二个条件(“OR”操作)。不要忘记最后的
DenyAllFilter
。我编写了一个自定义过滤器一次 ,也许这对创建过滤器有帮助。
两个附加程序可能是一种解决方法,但如果您想记录到一个文件,则存在可以解决的锁定问题(会造成性能损失)。
Log4net allows you to chain filters but this is works only as "OR". I think you could also make it do an "AND" operation but not really what you want. I would write my own filter that checks if the level and the pattern match. Then chain two instances of this filter to make it check the first condition and the second condition ("OR" operation). Do not forget the
DenyAllFilter
at the end.I wrote a custom filter once, maybe this is helpful for creating your filter.
Two appenders might be a workaround, but if you want to log to a file you have locking issues which can be resolved (with performance penalty).
您应该看看人们要求 AND 和 OR 过滤器的情况: Log4Net 过滤器“OR”
我知道,还没有实现任何东西,但是如果您确实需要它,您可以通过自己子类化 FilterSkeleton 来实现这一点。
You should have a look at people asking for AND and OR filters: Log4Net filters "OR"
As Far As I Know, there is nothing implemented yet, but in case you realy need it you could do the trick by subclassing FilterSkeleton yourself.