Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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");

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.

Can I set my configuration file to ignore the messages from a specific class?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
359 views
Welcome To Ask or Share your Answers For Others

1 Answer

Sure, use a filter.

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...