You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Francois Botha <ig...@gmail.com> on 2015/08/07 14:00:45 UTC

Log4Net Logging of two different levels to two different appenders for the same logger

Hi,

Please refer to the question and answer in
http://stackoverflow.com/a/21188397/179494 .

I have a similar config (see below), but at the moment DEBUG statements
(and above) also print in the console. My understanding is that with this
config, only ERROR and above should print in the console, but all levels
should print in the rolling file. What am I doing wrong?

My config:

  <log4net debug="false">
    <appender name="rollingFile"
type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="logs\log.txt" />
      <param name="AppendToFile" value="false" />
      <param name="RollingStyle" value="Date" />
      <param name="DatePattern" value="yyyy.MM.dd" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout,log4net">
      <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>

    <appender name="console" type="log4net.Appender.ColoredConsoleAppender,
log4net">
      <mapping>
        <level value="FATAL" />
        <foreColor value="Yellow, HighIntensity" />
        <backColor value="Purple, HighIntensity" />
      </mapping>
      <mapping>
        <level value="ERROR" />
        <foreColor value="White" />
        <backColor value="Red" />
      </mapping>
      <mapping>
        <level value="WARN" />
        <foreColor value="Yellow" />
      </mapping>
      <mapping>
        <level value="INFO" />
        <backColor value="Blue" />
        <foreColor value="White" />
      </mapping>
      <mapping>
        <level value="DEBUG" />
        <foreColor value="Green" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%c %-5p %m%n" />
      </layout>
    </appender>

    <root>
      <level value="DEBUG" />
      <appender-ref ref="console">
        <threshold value="ERROR" />
      </appender-ref>
      <appender-ref ref="rollingFile" />
    </root>
  </log4net>

thanks
Francois Botha

Re: Log4Net Logging of two different levels to two different appenders for the same logger

Posted by Gert Kello <ge...@gmail.com>.
Please refer to the question and answer in
http://stackoverflow.com/a/21188397/179494 .

>
> I have a similar config (see below), but at the moment DEBUG statements
> (and above) also print in the console. My understanding is that with this
> config, only ERROR and above should print in the console, but all levels
> should print in the rolling file. What am I doing wrong?
>
> My config:
>
>     <appender name="console"
> type="log4net.Appender.ColoredConsoleAppender, log4net">
>       <mapping>
>         <level value="FATAL" />
>         <foreColor value="Yellow, HighIntensity" />
>         <backColor value="Purple, HighIntensity" />
>       </mapping>
>
>

AFAIK the threashold goes to <appender> element, not to <appender-ref>
i.e.
<appender name="console" type="log4net.Appender.ColoredConsoleAppender,
log4net">
      <threshold value="ERROR" />
      <mapping>
        <level value="FATAL" />

Gert