I'm using the below log4net configuration. I'm trying to write performance logs to a separate file but the output is going to both files. Even though I'm specifiying:
private static readonly log4net.ILog log = log4net.LogManager.GetLogger("PerformanceMetricsLogger");
How do I stop log4net from writing to the default appender in this case?
<log4net>
<!-- Define some output appenders -->
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="c:\ilap\IlapAdServerLog_%property{log4net:HostName}.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="2000KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppenderForPerformance" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="c:\ilap\IlapAdServerLog_%property{log4net:HostName}.peformance.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="-1" />开发者_如何学Go;
<maximumFileSize value="2000KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
<logger name="PerformanceMetricsLogger">
<level value="DEBUG" />
<appender-ref ref="RollingFileAppenderForPerformance" />
</logger>
</log4net>
All the logger levels below root inherit the appenders from the root logger. This is why your messages are logged twice. To disable inheritance of your logger set its additivity parameter to false:
<logger additivity="false" name="PerformanceMetricsLogger">
<level value="DEBUG" />
<appender-ref ref="RollingFileAppenderForPerformance" />
</logger>
精彩评论