Saturday, February 04, 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: RollingFileAppenders per Class
Prev Next
You are not authorized to post a reply.

Author Messages
Hadley Willan

02/11/2009 2:39 AM  

Hi peoples,

 

I've used log4net for a while, but I've got the following problem.

 

I have a rolling file appender that takes everything, we'll call this the "VerboseAppender", easily configured.  ALL levels go to it and everything gets logged.

 

I have an ADO.Net appender that takes ERROR,FATAL level and logs to a stored procedure. We'll call this the "DBAppender"

 

But, we’ve got an annoying set of printer classes, that tend to spew masses of errors sometimes. These live under MyNamespace.StaticClassX.

What we need to do is add a separate local rolling file appender "NamespaceClassApppender", that takes only logs messages from MyNamespace.StaticClassX and logs them.

Then I need exlcude anything for MyNamespace.StaticClassX from the VerboseAppender and the DBAppender.

 

Is the best way to do this with Filters?

 

Basically each appender needs the following?

VerboseAppender, IF you're NOT MyNamespace.StaticClassX  log it

DBAppender,  (same as above)

NamespaceClassApppender, IF you ARE MyNamespace.StaticClassX log it, otherwise ignore it.

 

Thanks in advance.

Hadley


************************************************************************
Bunnings Legal Disclaimer:

1) This email is confidential and may contain legally privileged
information. If you are not the intended recipient, you must not
disclose or use the information contained in it. If you have received
this email in error, please notify us immediately by return email and
delete the document.

2) All emails sent to and sent from Bunnings Group Limited.
are scanned for content. Any material deemed to contain inappropriate
subject matter will be reported to the email administrator of all
parties concerned.
************************************************************************
Nick Durcholz

02/11/2009 3:32 PM  

I think what you want to do is use the logger heirarchy for this.  Something like the following will work:

<log4net debug="true">
  <appender name="VerboseAppender" type="...">
    ...
  </appender>
  <appender name="DBAppender" type="...">
    ...
  </appender>
  <appender name="NamespaceClassApppender" type="...">
    ...
  </appender>
  <root>
    <level value="ALL"/>
    <appender-ref ref="VerboseAppender"/>
    <appender-ref ref="DBAppender"/>
  </root>
  <logger name="MyNamespace.StaticClassX" additivity="false">
    <level value="ALL" />
    <appender-ref ref="NamespaceClassAppender" />
  </logger>
</log4net>


The key here is the additivity="false" attribute on MyNamespace.StaticClassX logger.  This indicates that the logger doesn't inherit appenders and other settings from the root logger, so messages sent to that logger are only sent to NamespaceClassAppender and not VerboseAppender or DBAppender.

Hadley Willan

02/12/2009 12:57 AM  

Thanks Nick,

That works a charm!

:)

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > RollingFileAppenders per Class



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