logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ITemplate <itempl...@hotmail.com>
Subject Re: Possible to test log4net filters on certain logevent?
Date Mon, 26 Apr 2010 08:33:43 GMT

Thanks Ron, very interesting. That interface also explains why log4net
accepts an object - I like this. I will look into your suggestions, thanks.

-- 
Werner



Ron Grabowski wrote:
> 
> Have you looked into writing an log4net.ObjectRenderer.IObjectRenderer to
> render the message as text or is that not that possibility?
> 
> Maybe this will work:
> 
> // untested
> public class WouldLogAppender : ForwardingAppender
> {
>  public bool WouldLog(LoggingEvent loggingEvent)
>  {
>  return FilterEvent(loggingEvent);
>  }
> }
> 
> You'd have to put your filters and thresholds on the WouldLogAppender
> instead of on the wrapped appender.
> 
> 
> ----- Original Message ----
> From: ITemplate <itemplate@hotmail.com>
> To: log4net-user@logging.apache.org
> Sent: Thu, April 15, 2010 3:36:20 AM
> Subject: Re: Possible to test log4net filters on certain logevent?
> 
> 
> Hi Loren,
> 
> Thanks for your reply! Well there are a couple of reasons but as an
> example,
> we need to log special webservices where the request and responses are
> VERY
> large objects that log4net (or any other) can't serialize correct. We have
> our own serializer for that job. But at the same time, these web services
> must perform well and object serialization here is a rather expensive and
> time consuming task. So I would like the ability to test if the log system
> would actually log the data - and if not, I would not even begin to
> serialize the classes to text.
> 
> But on the other hand I will not begin to dig too deep into log4net to
> accomplish this - it would only make sense if there were some easy way
> like:
> 
> var mustSerialize = false
> foreach(var appender in log4net.Appenders)
> {  
>   mustSerialize = appender.WouldLog(logEvent);
>   if (mustSerialize) break;
> }
> 
> But digging deeper would drain the goal of saving the time to serialize I
> guess...
> 
> -- 
> Werner
> 
> 
> 
> Loren Keagle wrote:
>> 
>> 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
>>>
>>>    
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://old.nabble.com/Possible-to-test-log4net-filters-on-certain-logevent--tp28188373p28252058.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context: http://old.nabble.com/Possible-to-test-log4net-filters-on-certain-logevent--tp28188373p28362157.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message