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 are going for in this case would be
log4net.Filter.LoggerMatchFilter ----(Matches against a the start of the
logger name.)
Hint: In the config
file for Log4Net it is 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.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFile.PassedDevices" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="Foo.namespace.bar.mySubclass" />
<acceptOnMatch value="false" />
</filter>
<file value="myPassedDevices.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%timestamp %level - %message [%thread] %logger%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" /> <!-- My other appender which logs all and I cut it out in this snippet. Remember that you should reference all your appenders in this tag to make them work.-->
<appender-ref ref="RollingFile.PassedDevices" />
</root>
</log4net>
</configuration>
In this technique you can have multiple appenders
which you can redirect the logging results of a specific logger to a separate appender
instead of ignoring them. Such as one appender
for all logs and one for the filtered out logs for a specific class
.