2

In my project I use log4net for logging. My project has a reference to a DLL, which also uses log4net for logging. 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?

4

2 回答 2

4

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

(从这里复制 XML )

于 2013-09-11T22:39:37.887 回答
1

您需要为您的命名空间创建一个记录器

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

然后只有在该命名空间中的登录才会被发送到 YourAppender。

于 2013-09-11T22:35:46.823 回答