I don't think that this is possible without some dangerous coding.
Looking at the source code, there are no methods on any appenders to
test the level/filter chain in advance. Given that your log4net config
could contain dozens of appenders, each with their own set of filters,
you could not make a single call to determine if an event would be
filtered from all of them. Perhaps if you provided a little bit of
context, someone here might be able to offer an alternative approach?
If you really must have a programmatic way of doing this, you would have
to gain access to all of your appenders, iterate through them, casting
each to AppenderSkeleton (assuming the appender derives from this helper
class!!!), test the log level of each, then iterate through all of the
filters in the FilterHead linked list property. AppenderSkeleton has a
protected method called FilterEvent that does all of this, but you
cannot access it. It would probably have solved your problem if this
method was part of the IAppender interface, but it's currently not
accessible.
So I suppose it is possible, but you're going to end up duplicating all
of the logic that is already in AppenderSkeleton, which means you will
be executing code twice. If you have multiple appenders, you will have
to check each appender separately.
~Loren Keagle
On 4/13/2010 6:18 AM, ITemplate wrote:
Noone knows? Perhaps I could rephrase: I need a programmatic way to determine
if a certain logentry would be filtered or not.
Example: I have the following logentry:
logger.Warn("This might be logged but I dont know. I want to test it in
code.");
Now I want to find out - at runtime - if that specific line in my code will
produce a log. Some programmatic way to test one or all configured filters
against the data in my log-line (Logger, Level, text etc).
Hope my meaning here is more clearer?
Thanks.
ITemplate wrote:
Hi,
Is this "old" forum the only for log4net? Anyways - suppose I have a
certain logevent, is it possible to investigate up front IF that
particular logevent would pass all filters? I can't seem to find a Filters
collection that I can use for this?
--
Werner
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.801 / Virus Database: 271.1.1/2807 - Release Date: 04/12/10
11:32:00