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.
| Author |
Messages |
|
Daniel Bigham
 |
| 10/01/2008 11:27 PM |
|
Hi,
I'm trying to create a chained logger according to the following logic:
if ( condition1 == true && condition2 == true ) { accept }
How can this be specified in XML?
Here is what I have tried:
<appender name="SupportToolAppender" type="log4net.Appender.AdoNetAppender"> <filter type="log4net.Filter.PropertyFilter"> <acceptOnMatch value="false" /> <key value="eventid" /> <regexToMatch value="\d+" /> <next type="log4net.Filter.LevelRangeFilter"> <acceptOnMatch value="true" /> <levelMin value="INFO" /> <levelMax value="FATAL" /> </next> </filter> <filter type="log4net.Filter.DenyAllFilter" /> ... </appender>
I guess more specifically my question is how the "next" property can be used to define the next logger in the chain. The above doesn't seem to work. I've tried some other things such as:
<next> <filter ...> ... </filter> </next>
... but that doesn't work either.
I don't see any documentation on the log4net site that explains how this is to be done, and Googling it hasn't helped much either.
Thanks, Daniel
-- Daniel Bigham Software Developer
Navtech, Inc. 295 Hagey Blvd., Suite 200 Waterloo, Ontario, N2L 6R5 tel: (519) 747 1170 x.301 fax: (519) 747-1003 dbigham@navtechinc.com
-- Daniel Bigham Software Developer
Navtech, Inc. 295 Hagey Blvd., Suite 200 Waterloo, Ontario, N2L 6R5 tel: (519) 747 1170 x.301 fax: (519) 747-1003 dbigham@navtechinc.com
|
|
|
|
|
Ron Grabowski
 |
| 10/01/2008 11:47 PM |
|
When the xml config file is being parsed the nodes in the config file are matched to properties on the appender. When multiple properties need to be set log4net looks for a method beginning with the word "Add". Most (all?) the appenders in log4net extend AppenderSkeleton. AppenderSkeleton has an AddFilter method which is how multiple filters can be added to an appender via the config file:
<appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="log.txt" /> <!-- AppenderSkeleton.AddFilter is called for each filter node --> <filter> <filter type="Company.Logging.CustomFilter1" /> <filter type="Company.Logging.CustomFilter2" /> <filter type="log4net.Filter.DenyAllFilter" /> </filter> </appender>
This blog post might be helpful to you:
http://weblogs.asp.net/tgraham/archive/2007/03/15/a-realistic-log4net-config.aspx
|
|
|
|
|
Daniel Bigham
 |
| 10/02/2008 3:42 PM |
|
Thanks for your reply Ron.
I tried structuring my filters as you suggest, but the behavior is:
if ( condition1 == true || condition2 == true ) { accept }
What I'm looking for is:
if ( condition1 == true && condition2 == true ) { accept }
I also took a look at the blog post you mentioned and again the behavior suggested is:
if ( condition1 == true || condition2 == true ) { accept }
Thanks, Daniel
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|