logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Meera Rajaram" <mraja...@vitalimages.com>
Subject RE: Using BufferingForwardingAppender based on size of message vs number of messages
Date Thu, 13 Apr 2006 13:37:49 GMT
The aim is to define a limit on the size of the messages that get
written to the log at one go. So we may want to buffer messages upto
10KB size before writing it to the log. 

If we simply take the size of the RenderedMessage (before applying the
layout), it does not accurately represent the message that gets written
to the log - since the actual message that gets written depends on the
layout that is applied. 

If we carry out buffering based on number of messages - then that does
not give an accurate picture too - since some messages may be longer
than others. 

If getting the actual message size (depending on the layout) is a
problem, I could use the solution that checks the RenderedMessage. Since
that seems to work really well.


-----Original Message-----
From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Wednesday, April 12, 2006 11:41 PM
To: Log4NET User
Subject: RE: Using BufferingForwardingAppender based on size of message
vs number of messages

Appenders define their own layout. One appender could use a simple
"%message%newline" pattern while another could use the more verbose
XmlLayoutSchemaLog4j layout.

Isn't it going to be difficult to get all the appenders to flush at the
same time if their layouts are all different?

I had an idea of extending BufferingForwardingAppender and overriding
its AddAppender method to make sure TextWriterAppender being added had
their QuietTextWriter property set to a CountingQuietTextWriter. After
each append, you could retrieve the Count property from the
CountingQuietTextWriter and generate a simple key based on the
appender's name and store that value in the Repository's property bag
so the evaluator can access it and decide if it needs to issue a flush:

 <appender name="MyBufferingForwardingAppender" 
  type="Company.Logging.BufferingForwardingAppender" >
  <evaluator type="RenderedMessageLengthEvaluator">
   <appender-ref ref="FileAppender1" />
   <flushOnRenderedMessageLength value="5000000" />
  <evaluator type="RenderedMessageLengthEvaluator">
   <appender-ref ref="FileAppender2" />
   <flushOnRenderedMessageLength value="10000000" />

Buffering up 10mb of data in memory then writing it to an appender will
probably cause your application to slowdown a bit don't you think?

Confused yet? I am :-) I don't think the BufferingForwardingAppender
can do what you need it to do. Maybe there's a different solution.
Could you give us more detail as to what you're trying to accomplish?

--- Meera Rajaram <mrajaram@vitalimages.com> wrote:

> Thanks Ron! This works great!! The only problem that I am having now
> is
> that the size of the message is currently considering just the
> RenderedMessage.Length - but I need to get the total size of the
> message
> after the layout has been applied. So if I am using Xml layout, I
> need
> to get the size of the entire xml message that would get written for
> that logging event. Is there any way to get this?
> Thanks,
> Meera.

This email has been scanned for all viruses and found to be virus free.
If you have questions regarding this scanning please visit the
Information Services area of http://home.vitalimages.com

View raw message