logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Multiple Layouts to the same appender
Date Sat, 23 Aug 2008 01:16:00 GMT
You shouldn't be using a layout on the ForwardingAppender. The ForwardingAppender always ignores
that value. log4net doesn't concatenate the layout from your ForwardingAppender with the Console/RollingFileAppender.

You'll have to copy the %m to the Console/RollingFileAppenders' layout.



----- Original Message ----
From: Loren Keagle <Loren@aps-technology.com>
To: log4net-user@logging.apache.org
Sent: Friday, August 22, 2008 8:01:57 PM
Subject: Multiple Layouts to the same appender

I have an application that contains a subsystem with its own logging 
infrastructure.  I can hook into this logging system to intercept the 
log messages, but the messages are already formatted.  Rather than parse 
and decompose these messages, I simply used a PatternLayout to match the 
layout of the subsystem.


However, I also need to log from my own code to the same file.  This 
means I need to have an empty layout for the logger that's logging the 
subsystem messages, and a formatted layout for all the other loggers.  
I've tried using a ForwardingAppender, and setting a layout in there, 
but that layout is overridden by the layout in the FileAppender.  If I 
leave the layout off of ForwardingAppender, I get a log4net error.

It seems as though the chain of responsibility is reversed for the 
layouts than what it should be... Shouldn't log4net use the first layout 
it finds as it traces up the hierarchy, rather than the root layout?  
Why is the layout in my ForwardingAppender ignored?

Here is my config block:

<log4net>
   <appender name="ConsoleAppender" 
type="log4net.Appender.ConsoleAppender" >
     <layout type="log4net.Layout.PatternLayout">
       <ConversionPattern value=" %d{HH:mm:ss.fff} %14c{1} %m%n" />
     </layout>
   </appender>
   <appender name="RollingFileAppender" 
type="log4net.Appender.RollingFileAppender">
     <file value="log.txt" />
     <appendToFile value="true" />
     <rollingStyle value="Size" />
     <maxSizeRollBackups value="5" />
     <maximumFileSize value="10MB" />
     <staticLogFileName value="true" />
     <layout type="log4net.Layout.PatternLayout">
       <ConversionPattern value=" %d{HH:mm:ss.fff} %14c{1} %m%n" />
     </layout>
   </appender>
   <appender name="ForwardingAppender" 
type="log4net.Appender.ForwardingAppender" >
     <appender-ref ref="ConsoleAppender" />
     <appender-ref ref="RollingFileAppender" />
     <layout type="log4net.Layout.PatternLayout">
       <ConversionPattern value="%m" />
     </layout>
   </appender>
   <root>
     <level value="DEBUG" />
     <appender-ref ref="RollingFileAppender" />
     <appender-ref ref="ConsoleAppender" />
   </root>
   <logger name="subsystem" additivity="false" >
     <appender-ref ref="ForwardingAppender" />
   </logger>
</log4net>

Mime
View raw message