简体   繁体   English

log4net:如何关闭程序集引用的日志记录?

[英]log4net: How to turn off logging of an assembly reference?

In my project I use log4net for logging. 在我的项目中,我使用log4net进行日志记录。 My project has a reference to a DLL, which also uses log4net for logging. 我的项目引用了一个DLL,它也使用log4net进行日志记录。 Now I am facing the problem, that my logfile has both outputs: The messages from my own code and also the messages from the reference. 现在,我面临的问题是,我的日志文件同时具有两个输出:来自我自己的代码的消息以及来自引用的消息。

How can I turn off logging for the referenced DLL? 如何关闭引用DLL的日志记录?

Alternatively to Ash Burlaczenko's answer, you could also filter those messages from the foreign namespace, like so: 除了Ash Burlaczenko的答案,您还可以过滤来自外部名称空间的消息,如下所示:

<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>

(Copied XML from here ) (从此处复制XML)

You need to create a logger just for your namespace 您只需要为名称空间创建一个记录器

<logger name="YourNamespace.SubNamespace">
    <appender-ref ref="YourAppender" />
</logger>

Then only logging in that namespace will be sent to YourAppender. 然后,仅登录该名称空间将被发送到YourAppender。

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

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