logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "N@poleone" <napoleone1...@gmail.com>
Subject Re: Different pattern layout based on Level
Date Tue, 05 May 2009 09:42:34 GMT
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

Mime
View raw message