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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Francois Botha
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
Reply | Threaded
Open this post in threaded view
|

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

Gert Kello
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