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?
I would suggest using Filters as well. However, since I struggled finding the whole picture when I was trying to implement the filter I am posting a sample snippet of the
Configutation file
I created which points out where filters go.The filter you're goning for in this case would be
Hint in the
config
file for Log4Net it's important where you put your tags and the priority of them actually matters. So in this case<filter>
tag comes after the<appender>
opening tag and before it's<file value = ... />
tag.In this technique you can have multiple
appenders
which you can redirect the logging results of a specific logger to a separateappender
instead of ignoring them. Such as oneappender
for all logs and one for the filtered out logs for a specificclass
.A filter certainly works but I would prefer to turn off the logger (or logger hierarchy) directly like this:
Assuming that
YourNameSpace.WithNoLogging
is a namespace then the shown configuration would disable logging on the entire name space. The second "example" turns off logging for your class (according to your question).You might want to try to apply a category to your own messages Try this thread: How to add category prefix to log4net message?
Sure, use a filter.
Here's the snippet posted on the blog, for future reference - all credit to the author of that blog post: