If you do something like this: <appender name="BFA" type="log4net.Appender.BufferingForwardingAppender" > <bufferLength value="10000" /> <appender-ref ref="ConsoleAppenderWithSimplePatternLayout" /> <appender-ref ref="FileAppenderWithSimpleLayout" /> <appender-ref ref="FileAppenderWithPatternLayout" /> <appender-ref ref="FileAppenderWithLog4JLayout" /> </appender>
its going to be very difficult to properly manage when things will flush. Each of those appenders could be on a very different flush cycle depending on their layout. The BufferingForwardingAppender works well when just the number of messages are buffered becuase that number isn't volatile like the rendered message length. In the example above, 10k might be a good buffer length for a FileAppender on the local file system but not for a network share FileAppender or the DebugAppender. I think a better starting point would be to write a BufferedRenderedMessageLengthFileAppender (long name!) and put the bufferLength property on that. What other appenders besides the FileAppender do you think would benefit from this? --- Meera Rajaram <[EMAIL PROTECTED]> wrote: > 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. > > Thanks, > Meera. > > -----Original Message----- > From: Ron Grabowski [mailto:[EMAIL PROTECTED] > 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> > <evaluator type="RenderedMessageLengthEvaluator"> > <appender-ref ref="FileAppender2" /> > <flushOnRenderedMessageLength value="10000000" /> > </evaluator> > </appender> > > 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 <[EMAIL PROTECTED]> 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 > ________________________________________________________________________ >
