log4net - how do I set DEBUG for my Console output, and INFO for my FileAppender?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2010-03-30T23:23:26Z Indexed on 2010/03/31 5:43 UTC
Read the original article Hit count: 452

Hi,

I haven't quite worked this one out yet - how do I set DEBUG for my Console output, and INFO for my FileAppender? That is, how would I change the configuration below so that I can get the ConsoleAppender pumping out all logging from DEBUG upwards? Note that both appenders need to cover all logging (i.e. I don't want to use a scoped logger element that changes the log level for just one logger name)

  <log4net>

    <root>
      <level value="INFO" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>

    <appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
      <param name="File" value="log-file.txt" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="Header" value="[Header]\r\n"/>
        <param name="Footer" value="[Footer]\r\n"/>
        <param name="ConversionPattern"
           value="%d [%t] %-5p %c [%x] - %m%n"
        />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value="DEBUG" />
        <param name="LevelMax" value="WARN" />
      </filter>
    </appender>

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>

  </log4net>

© Stack Overflow or respective owner

Related posts about log4net

Related posts about log4netconfiguration