Thursday, March 11, 2010
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Parameterizing appenders with a conversion pattern according to the level
Prev Next
You are not authorized to post a reply.

Author Messages
Jo Vermeulen

10/22/2007 10:58 AM  

Hello,

I now have different console appenders according to the specific level
I use. I have a problem appender, an info appender and a debug
appender. I use filters and tresholds to limit the levels these
appenders process.

However, the only difference between them is the conversion pattern
that is used. Info messages are just written to the console, while
warn or error messages get their level printed as well. Debug messages
have all the information that's available (thread, ndc, logger object,
...).

It seems a bit stupid to create different appenders for this.
Furthermore, if I want to go into debug mode, I would like every
appender to use this detailed log format (also INFO and WARN
messages).

I was thinking about solving this using parameters, but I'm not sure
how I can do that. Here's my current config file:

====================
<?xml version="1.0" encoding="utf-8" ?>

<log4net>

    <!-- Define some output appenders -->

    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">

        <file value="uiml.net.log" />


        <appendToFile value="true" />

        <layout type="log4net.Layout.PatternLayout">

            <header value="[Header]&#13;&#10;" />

            <footer value="[Footer]&#13;&#10;" />

            <conversionPattern value="%date [%thread] %-5level %logger
[%ndc] &lt;%property{auth}&gt; - %message%newline" />

        </layout>

    </appender>

    <!-- This appender is used for INFO level messages -->

    <appender name="InfoAppender" type="log4net.Appender.ConsoleAppender">

        <filter type="log4net.Filter.LevelMatchFilter">

            <levelToMatch value="INFO" />

        </filter>

        <layout type="log4net.Layout.PatternLayout">

            <conversionPattern value="%message%newline" />

        </layout>

    </appender>

    <!-- This appender is used for DEBUG, WARN and ERROR messages -->

    <appender name="ProblemAppender"
type="log4net.Appender.AnsiColorTerminalAppender">

        <mapping>

            <level value="ERROR" />

            <foreColor value="White" />

            <backColor value="Red" />

            <attributes value="Bright,Underscore" />

        </mapping>

        <mapping>

            <level value="WARN" />

            <foreColor value="White" />

            <backColor value="Yellow" />

            <attributes value="Bright" />

        </mapping>

        <threshold value="WARN" />

        <layout type="log4net.Layout.PatternLayout">

            <conversionPattern value="%-5level: %message%newline" />

        </layout>

    </appender>

    <!-- This appender is used for DEBUG messages -->

    <appender name="DebugAppender"
type="log4net.Appender.AnsiColorTerminalAppender">

        <mapping>

            <level value="DEBUG" />

            <foreColor value="White" />

            <backColor value="Blue" />

            <attributes value="Bright" />

        </mapping>

        <filter type="log4net.Filter.LevelMatchFilter">

            <levelToMatch value="DEBUG" />

        </filter>

        <layout type="log4net.Layout.PatternLayout">

            <conversionPattern value="%date [%thread] %-5level %logger
[%ndc] &lt;%property{auth}&gt; - %message%newline" />

        </layout>

    </appender>

    <!-- Setup the root category, add the appenders and set the
default level -->

    <root>

        <level value="INFO" />

        <appender-ref ref="InfoAppender" />

        <appender-ref ref="ProblemAppender" />

    </root>

</log4net>

====================

Thanks in advance!

-- Jo

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Parameterizing appenders with a conversion pattern according to the level



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement