I would like to write to Console.Out when I do anything below logger.Warn and then I would like to write to Console.Err when I log anything logger.Error and above. How would I write my log4net config file?
So far I have:
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
You can create two appenders, and configure them differently. Something like (untested):
<log4net>
<appender name="ConsoleOutAppender" type="log4net.Appender.ConsoleAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="WARN" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="..." />
</layout>
</appender>
<appender name="ConsoleErrorAppender" type="log4net.Appender.ConsoleAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
<target value="Console.Error" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="..." />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleOutAppender" />
<appender-ref ref="ConsoleErrorAppender" />
</root>
</log4net>
EDIT: Corrected logic error with levelMin
vs. levelMax
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With