Friday, May 18, 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: Multiple Layouts to the same appender
Prev Next
You are not authorized to post a reply.

Author Messages
Loren Keagle

08/23/2008 2:01 AM  

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>

Ron Grabowski

08/23/2008 3:16 AM  

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.

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Multiple Layouts to the same appender



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