Thanks. I will take yours and Loren's thougts with me to our next developer
meeting. Although I'm new to log4net, I have to say that I'm willing to
fight to get this into our new applications. It is so easy to use compared
to our current (entlib) log system.

-- 
Werner


Walden H. Leverich wrote:
> 
> Werner, Loren's check of IsDebugEnabled is the accepted way to accomplish
> what you want. Beyond that though, if you're usage is like ours then most
> of the time (99.999999999999999999% :-) you don't want the logging of
> those large objects at all, but every once in a while you do. Well, we
> accepted that we'd have to restart the application to get it, and we added
> a static _readonly_ variable that we check in addition to IsDebugEnabled.
> Since it's static readonly, the JIT knows it can't be updated once it's
> set and will actually omit the logging from the generated machine code --
> it's one performance step beyond IsDebugEnabled.
> 
> -Walden
> 
> 
> -- 
> Walden H Leverich III
> Tech Software & 
> BEC - IRBManager
> (516) 627-3800 x3051
> wald...@techsoftinc.com
> http://www.TechSoftInc.com
> http://www.IRBManager.com
> 
> Quiquid latine dictum sit altum viditur.
> (Whatever is said in Latin seems profound.)
> 
> 
> -----Original Message-----
> From: ITemplate [mailto:itempl...@hotmail.com] 
> Sent: Thursday, April 15, 2010 3:36 AM
> To: log4net-user@logging.apache.org
> 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--tp28188373p28265740.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply via email to