Monday, May 21, 2012
 
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: Re: Different pattern layout based on Level
Prev Next
You are not authorized to post a reply.

Author Messages
N@poleone

05/05/2009 11:42 AM  
Hi,
my goal is to have different pattern layout based on the Level of the Logger. This cause I'd want to include line, method name etc. only if debug level is on.

Cause the appender section can include only one child element of type layout, I'm trying using two different appenders:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="Data\logs\logfile" />
    <appendToFile value="true" />
    <rollingStyle value="Composite" />
    <datepattern value="-yyyy-MM-dd.'log'" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <staticLogFileName value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{ISO8601} | %-5level | [%thread] | %logger | %message %exception %newline" />
    </layout>
    <evaluator type="log4net.Core.LevelEvaluator">
      <threshold value="INFO"/>
    </evaluator>
  </appender>

  <appender name="RollingFileAppenderDebug" type="log4net.Appender.RollingFileAppender">
    <file value="Data\logs\logfile" />
    <appendToFile value="true" />
    <rollingStyle value="Composite" />
    <datepattern value="-yyyy-MM-dd.'log'" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <staticLogFileName value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{ISO8601} | %-5level | [%thread] | %logger | %type | %method | %line | %message %exception %newline" />
    </layout>
  </appender>

  <root>
    <level value="INFO" />
    <appender-ref ref="RollingFileAppenderDebug" />
    <appender-ref ref="RollingFileAppender" />
  </root>

With this file I've some problem:

1) The two appenders doesn't log to the same file like I'd want... but I see two file named logfile-yyyy-MM-dd.log and logfile-yyyy-MM-dd.log-yyyy-MM-dd.log. The question is: How can I use tow RollingFileAppenders to log on the same file??

2) If I activate Debug then I'll have duplicate logs for every log statement from Info and above, right??

One solution could be to remove one appender at runtime based on the level specified: Info and above I'll remove the RollingFileAppenderDebug, Debug I'll remove the RollingFileAppender. How can I accomplish this??

Thanks to all.

N@poleone
You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Re: Different pattern layout based on 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