We have two different asp.net applications with Log4net logging enabled. They both have the same version of Log4Net, 1.2.10.0.
We have added the log4net.Append
You could specify a LevelRangeFilter
for each of the appenders, and define each appender in the root to log at different levels.
<appender name="filelogAppender" type="log4net.Appender.RollingFileAppender" >
<!--File Details/Layout Options-->
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO"/>
</filter>
</appender>
<appender name="dbLogAppender" type="log4net.Appender.AdoNetAppender">
<!--SQL Options-->
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR"/>
</filter>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="filelogAppender" /> <!--Prints info, warn, error, or fatal logs. -->
<appender-ref ref="dbLogAppender" /> <!--Prints only error or fatal logs. -->
</root>
Simply use Evaluator, you do not need to give threshold in all the appenders.
<appender name="filelogAppender" type="log4net.Appender.RollingFileAppender">
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR" />
</evaluator>
</appender>
You should be able to set the threshold
property of each appender separately and include them in the same root.
<appender name="filelogAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="Error" />
</appender>
<appender name="dblogAppender" type="log4net.Appender.AdoNetAppender">
<threshold value="Info" />
</appender>
<root>
<appender-ref ref="filelogAppender" />
<appender-ref ref="dblogAppender" />
</root>
reference
Two <root>
elements are not allowed.
From documentation:
root Optional element, maximum of one allowed. Defines the configuration of the root logger.
You can however have a root logger like you do, and then have a separate logger specified by a namespace.
<root>
<level value="Error"/>
<appender-ref ref="filelogAppender"/>
</root>
<logger name="MyCompany.MyApp.Namespace">
<level value="Info"/>
<appender-ref ref="dbLogAppender"/>
</logger>