是否可以在 log4net 配置中使用通配符记录器名称?
在我的应用程序中,我使用 log4net,所有类型都根据其类型创建自己的记录器 - 例如:
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
在开发时,我将根记录器保留为 DEBUG,以便捕获代码中的所有日志输出。
但是,第三方组件也使用相同的方法,但每秒生成 100 条日志消息,我对这些消息都不感兴趣。
是否可以在记录器配置中使用某种通配符,以强制所有记录器仅在 WARN 处记录,例如:
<logger name="com.thirdparty.*">
<level value="WARN"/>
</logger>
[上面的确切示例,使用 * 不起作用]
In my application, I use log4net, with all types creating their own logger based on their type - e.g. :
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
As I am developing, I leave the root logger on DEBUG so as to catch all log output from my code.
However, a third party component also uses this same approach, but is generating 100s of log messages a second, none of which I am interested in.
Is it possible to use some sort of wildcarding in the logger configuration, to force all their loggers to only log at WARN, e.g. :
<logger name="com.thirdparty.*">
<level value="WARN"/>
</logger>
[The exact example above, using a * doesn't work]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以只指定命名空间的一部分,以便它将应用于该命名空间内的所有消息(包括嵌套的消息)。
这是我经常使用的示例:
另外,我建议阅读手册。它提供了很多解释。例如,您可以阅读Logger Hierarchy。这是那里的引用:
还有:
You can just specify part of a namespace so it will apply to all messages within that namespace (including nested).
Here is the example I often use:
Additionally I would recommend to read the manual. It provides a lot of explanation. For example you can read about Logger Hierarchy. Here is the quote from there:
and also:
你不能做与你要求相反的事情吗?我的意思是将默认日志级别设置为“警告”,然后将您定义的特定记录器设置为“调试”。
此外,您可以将附加程序的阈值设置为“调试”,并让其他附加程序设置“警告”。
例如:
Can't you do the opposite of what you're asking. What I mean is just set the default log level to warn and then set the specific loggers you have defined to DEBUG.
Also, you could set the threshold of your appender to DEBUG and have the other appender set the WARN.
For example: