I would suggest using Filters . However, since I was trying to find the whole picture, when I was trying to implement a filter, I send a sample fragment created by the Configutation file , which indicates where the filters go.
The filter you are going to in this case will be
log4net.Filter.LoggerMatchFilter ---- (Same as the beginning of the logger name.)
The hint in the config file for Log4Net is important when you add tags and their priority actually matters. Thus, in this case, the <filter> tag appears after the <appender> and before it is the <file value = ... /> .
<?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" /> <appender-ref ref="RollingFile.PassedDevices" /> </root> </log4net> </configuration>
In this method, you can have several appenders that you can redirect the logging results of a particular registrar to a separate appender instead of ignoring them. For example, one appender for all logs and one for filtered logs for a particular class .
Mehrad Jun 05 '14 at 23:20 2014-06-05 23:20
source share