logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Lund" <ml...@control4.com>
Subject RE: Using thread context data from a filter to decide whether to append...
Date Mon, 15 Jun 2009 14:48:23 GMT
Bump J  Hoping for some feedback...

 

From: Matt Lund [mailto:mlund@control4.com] 
Sent: Thursday, June 11, 2009 11:16 AM
To: log4net-user@logging.apache.org
Subject: Using thread context data from a filter to decide whether to
append...

 

Hi all.  I'd like to know if I'm doing this correctly.  I want to set a
value in ThreadContext.Properties from application code.  I then want
some appenders to log or not log based on this contextual information.
I believe the right way to do this is to create a class that implements
IFilter and apply some filters to the these appenders.

 

So far I've created my filter class, and I've added the
ThreadContext.Properties["foo"] = "bar" to my application code.

 

Now, I'm looking at how to implement the Decide method on my filter
class.  I had assumed that the "foo"-"bar" information would be
available in the LoggingEvent that gets passed in to Decide but if it's
there, I don't see it.  However, if I directly access
ThreadContext.Properties["foo"] from inside the Decide method then that
works.  This seemed odd to me at first because I didn't know that
Decide() would always be called on the thread where the log.Info("etc")
call came from.  But if Decide() is always called on that thread, I
should be safe to access ThreadContext.Properties["foo"] from inside
Decide() - right?

 

If I'm not correct or there's a better way to access the
thread-contextual information from inside Decide() please let me know...

 


Mime
View raw message