log4net:配置为忽略来自特定类的消息 [英] log4net: Configure to ignore messages from a specific class
问题描述
有没有办法让 log4net 配置忽略特定的类?比如我们一般在每个班级都会创建一个日志.类似这样:
Is there a way to have the log4net configuration ignore a specific class? For example, we generally create a log in every class. Similar to this:
private static readonly ILog Log = log4net.LogManager.GetLogger("MyClass");
问题在于 MyClass
记录了大量数据,很难找到其他类的信息.它是另一个使用 MyClass
的开发人员,所以我不能只是进入并更改日志文件,但在我的环境中我想忽略这些.
The problem is MyClass
logs an extreme amount of data and it gets hard to find information about other classes. Its another dev that uses MyClass
so I cannot just go in and change around the log files, but in my environment I would like to ignore these.
我可以设置我的 configuration
文件以忽略来自特定类的消息吗?
Can I set my configuration
file to ignore the messages from a specific class?
推荐答案
当然,使用 过滤器.
这是发布在博客上的片段,以供将来参考 - 全部归功于该博客文章的作者:
Here's the snippet posted on the blog, for future reference - all credit to the author of that blog post:
<filter type="log4net.Filter.LoggerMatchFilter">
<!-- allows this sub-namespace to be logged... -->
<loggerToMatch value="Noisy.Namespace.But.Important" />
</filter>
<filter type="log4net.Filter.LoggerMatchFilter">
<!-- ...but not the rest of it -->
<loggerToMatch value="Noisy.Namespace" />
<acceptOnMatch value="false" />
</filter>
这篇关于log4net:配置为忽略来自特定类的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!