logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Durcholz <NDUR...@e-farmcredit.com>
Subject RE: RollingFileAppenders per Class
Date Wed, 11 Feb 2009 14:32:45 GMT
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.
________________________________

From: Hadley Willan [mailto:HWillan@bunnings.com.au] 
Sent: Tuesday, February 10, 2009 8:39 PM
To: Log4NET User
Subject: RollingFileAppenders per Class



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.
************************************************************************


Mime
View raw message