logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ross Hinkley <rosshink...@gmail.com>
Subject Re: Piping log messages to different appenders via LEVEL
Date Thu, 16 Dec 2010 15:37:38 GMT
You should be able to use the Threshold tag under the appender to specify
what level you'd like to start logging.  The threshold is inclusive.

The log4net SDK outlines how it works:
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AppenderSkeleton.Threshold.html

I've modified your configuration below; I think it's correct.  Let me know
if you have trouble with it.

-Ross

On Thu, Dec 16, 2010 at 8:12 AM, Jesper Lund Stocholm <
jesper.stocholm@ciber.dk> wrote:

> I would like to send log messages to one of two appenders depending on the
> level of the message. Specifically, I’d like this:
>
>
>
> Everything: send to Console
>
> Error and above: send to file
>
>
>
> So I have configured these two appenders:
>
>
>
> <appender name="Console" type="log4net.Appender.ConsoleAppender">
>          <threshold value="ALL" />
>
    <layout type="log4net.Layout.PatternLayout">
>
>       <conversionPattern value="%date %-4timestamp [%thread] %-5level
> %logger %ndc - %message%newline" />
>
>     </layout>
>
> </appender>
>
>
>
> <appender name="RollingFileAppender" type="
> log4net.Appender.RollingFileAppender">
>   <threshold value="ERROR" />
>
>   <file value="C:\Windows\Temp\servicelog_01.txt" />
>
>   <appendToFile value="true" />
>
>   <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
>
>   <rollingStyle value="Size" />
>
>   <maxSizeRollBackups value="10" />
>
>   <layout type="log4net.Layout.PatternLayout">
>
>     <conversionPattern value="%date %-4timestamp [%thread] %-5level
> %logger %ndc - %message%newline" />
>
>   </layout>
>
>   <evaluator type="log4net.Core.LevelEvaluator">
>
>     <threshold value="ERROR"/>
>
>   </evaluator>
>
> </appender>
>
>
>
> I would have thought that adding the <evaluator>-element to the
> RollingFileAppender would filter the messages only saving the messages with
> level “ERROR and above”, but everything still gets send to both appenders.
>
>
>
> Can you tell me what I am missing here?
>
>
>
> Thanks,
>
>
>
> :o)
>
>
>
> Med venlig hilsen / Best regards
>
>
>
> Jesper Lund Stocholm
>
> Seniorarkitekt / Senior architect
>
>
>

Mime
View raw message