Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 34541 invoked from network); 15 Apr 2010 08:07:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 08:07:10 -0000 Received: (qmail 97792 invoked by uid 500); 15 Apr 2010 08:07:10 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 97562 invoked by uid 500); 15 Apr 2010 08:07:08 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 97554 invoked by uid 99); 15 Apr 2010 08:07:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 08:07:07 +0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=AWL,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.208.4.194] (HELO mout.perfora.net) (74.208.4.194) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 08:07:02 +0000 Received: from [192.168.0.201] (ip68-6-198-25.sd.sd.cox.net [68.6.198.25]) by mrelay.perfora.net (node=mrus2) with ESMTP (Nemesis) id 0LyVZ8-1NMvd23XV8-015iUS; Thu, 15 Apr 2010 04:06:40 -0400 Message-ID: <4BC6C90D.5090700@aps-technology.com> Date: Thu, 15 Apr 2010 01:06:37 -0700 From: Loren Keagle User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: log4net-user@logging.apache.org Subject: Re: Possible to test log4net filters on certain logevent? References: <28188373.post@talk.nabble.com> <28229862.post@talk.nabble.com> <4BC4AD71.2040403@aps-technology.com> <28252058.post@talk.nabble.com> In-Reply-To: <28252058.post@talk.nabble.com> Content-Type: multipart/alternative; boundary="------------000409070801060702000108" X-Provags-ID: V01U2FsdGVkX1+EzOLjgiXmqsoQNXfsE1p+V9yc5ol6C8w3/uA Sk1H4OsVBCbyZ3F13GNdyDzXwMQLV0q0p0VFiSOqMFmF8F0O7Z YZz990xRy/3ium3di5JemeMpgZC2+PO This is a multi-part message in MIME format. --------------000409070801060702000108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I think you can get halfway to your goal just by using the suggestions in the FAQ. If you only care to check the log level of your logger instance, and not the filter chains in the individual appenders, you can use the helper methods on the ILog interface. if (logger.IsDebugEnabled) { string s = customObject.Serialize(); logger.Debug("Custom serialized object: " + s); } Change the signature appropriately for Info, Error, Warn, or Fatal logging. If you do need to check if the logging would get past filters on the individual appenders, you'll have to download the source code and simply add the log4net project to your solution so you can edit the source. We do this in order to support custom logging levels lower than the Debug level. You could easily add a helper method to the ILog interface to check if an event would make it past all of the filters on all of the appenders. In the LogImpl class, create an implementation that iterates through all of the IAppenders and calls the FilterEvent method. However, since your custom object has not yet been serialized, filters that actually analyze the content of the log message would obviously not trigger! Hopefully the first solution will be all you need. ~Loren Keagle On 4/15/2010 12:36 AM, ITemplate wrote: > 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... > > > > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.801 / Virus Database: 271.1.1/2811 - Release Date: 04/14/10 11:31:00 > > --------------000409070801060702000108 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I think you can get halfway to your goal just by using the suggestions in the FAQ.  If you only care to check the log level of your logger instance, and not the filter chains in the individual appenders, you can use the helper methods on the ILog interface.

if (logger.IsDebugEnabled)
{
    string s = customObject.Serialize();
    logger.Debug("Custom serialized object: " + s);
}

Change the signature appropriately for Info, Error, Warn, or Fatal logging.

If you do need to check if the logging would get past filters on the individual appenders, you'll have to download the source code and simply add the log4net project to your solution so you can edit the source.  We do this in order to support custom logging levels lower than the Debug level.  You could easily add a helper method to the ILog interface to check if an event would make it past all of the filters on all of the appenders.  In the LogImpl class, create an implementation that iterates through all of the IAppenders and calls the FilterEvent method. 

However, since your custom object has not yet been serialized, filters that actually analyze the content of the log message would obviously not trigger!  Hopefully the first solution will be all you need.

~Loren Keagle

On 4/15/2010 12:36 AM, ITemplate wrote:
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...

  
No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.801 / Virus Database: 271.1.1/2811 - Release Date: 04/14/10 11:31:00

--------------000409070801060702000108--