You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Meera Rajaram <mr...@vitalimages.com> on 2006/04/12 00:44:55 UTC

Using BufferingForwardingAppender based on size of message vs number of messages

Sorry bout that. Didn't mean to hijack Daniel's thread. He had a note on
BufferingForwardingAppender in his thread, which is why I wanted to find
more info on it. 

My question is this: Currently in the BufferingForwardingAppender, the
number of messages to be buffered can be set using bufferSize. Is there
any way to carry out the buffering based on the size of the messages?
 
Thanks,
Meera.

-----Original Message-----
From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Tuesday, April 11, 2006 5:32 PM
To: Log4NET User
Subject: RE: Accessing Appender that was created via config file?

Please don't hijack someone's thread by asking your own unrelated
question.

The BufferingForwardingAppender does what you're asking:

http://tinyurl.com/j7t9s
http://logging.apache.org/log4net/release/config-examples.html#buffering
forwardingappender

Have you tried it in your application? Is something not working?

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

> I am using RollingFileAppender to log messages. Is there a way in
> which
> I can cache the messages before writing them out to the file? Ideally
> the cache size would be in the configuration file. When the total
> size
> of the messages (I need the writing to be done based on size of all
> messages and not based on number of cached messages) reaches the
> cache
> size, I need the messages to be written to the log file. I am new to
> log4Net so I am not sure if I can use BufferingForwardingAppender in
> some way to achieve this? 
> 
> Thanks,
> Meera.
> 
> -----Original Message-----
> From: Daniel Bachler [mailto:DanyX@gmx.net] 
> Sent: Tuesday, April 11, 2006 9:37 AM
> To: log4net-user@logging.apache.org
> Subject: Accessing Appender that was created via config file?
> 
> Hi all,
> 
> I am currently in the process of switching my app and a few libraries
> I
> wrote to log4net. So far everything works fine, but now I am at a
> point
> where I need the help of people who have more insight into log4net
> than
> me.
> 
> I want to accomplish two things: First I want an appender to output
> to a
> multiline textbox of my app. I think that this might be easiest by
> working
> with an appender similar to FireEventAppender from the examples, or
> are
> there other suggested ways to do this(*)? The second thing I want to
> achieve
> is a little trickier. My old, custom logging framework had a function
> called
> SetJob(string currentJob) that would output the string given to what
> is
> called the appenders in log4net, but there would be special handling
> to
> update a small label in the UI to inform the user of what the app is
> currently doing. I thought that the best way to get a similar
> behaviour
> was
> to log objects of type JobMessage or something to replace
> SetJob(currentJob), and writing a filter to filter based on type and
> an
> appender that would write this info to the UI. Again, it seems that
> something along the lines of FireEventAppender would be the easiest
> way
> to
> do this.
> 
> This brings me to the core question: FireEventAppender is implemented
> as
> a
> weird kind of singleton. Implementing something like
> FireEventAppender
> as a
> singleton would of course be possible, but then I could only have 1
> and
> would have to do the filtering (directing most output to the
> multiline
> textbox and some to the Current Job UI Label) myself. It seems to me
> that
> this is not entirely in the spirit of log4net, which is why I
> (finally)
> ask:
> Is there a possibility to get the reference to a certain Appender
> that
> was
> created via config file magic? Something similar to
> LogManager.GetLogger(),
> along the lines of LogManager.GetAppenderByName(string name)? If it
> isn't,
> do you have any suggestions on how to implement the behaviour
> described
> above?
> 
> TIA,
> Daniel
> 
> *) As a sidenote: Since some of my function can output a lot of
> messages
> within a short amount of time that I want to appear in the multiline
> textbox, I implemented a mechanism to store the messages in memory
> and
> append them to the multiline textbox via a timer event. The log4net
> BufferingForwardingAppender seems to be an alternative to this
> technique,
> but as far as I understand it there is no way to get the current
> implementation to output either every n seconds or whenever the
> buffer
> is
> full, whichever comes first. Is this correct? Is there an
> implementation
> that does it this way maybe?
> 
> --
> Daniel Bachler
> http://www.danyx.com
> Contact details: http://www.danyx.com/contact
> The attatched file starting with ATT is a signature for this message.
> To
> understand how you can verify my identity based on this signature,
> please go
> to http://www.danyx.com/WhyGPG
> 
> 


________________________________________________________________________
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
________________________________________________________________________

BufferingForwardingAppender, another question

Posted by Marco von Frieling <te...@gmx.de>.
Hi.

Yesterday I had the problem that an NHibernate operation took 3202 ms and
the complete callback about 6 seconds, which obviously is too long. So I
configured an extra logger for the NHibernate namespace hierarchy with level
INFO instead of DEBUG an the same operation has finished after 76 ms. But
logging root with DEBUG and NHibernate only with info does not work for us
during development. So I thaught it would be the best thing to use a
BufferingForwardingAppender forwarding to the FileAppender.

Then my project leader asked me what happens when the buffer configured to
200 messages contains only 100 messages when the request ends and no other
request comes in for a while. When will these 100 messages be written into
the log file, only if the buffer is full? Or is there a way to flush the
buffer when the current thread or process is idle?

Thanks, Marco

-- 
Marco von Frieling
In den Ackern 8
D-27374 Wittorf

eMail: teuchlfex1202@gmx.de

"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

Re: Using BufferingForwardingAppender based on size of message vs number of messages

Posted by Ron Grabowski <ro...@yahoo.com>.
The BufferingForwardingAppender supports an evaluator object
(ITriggeringEventEvaluator) whose IsTriggeringEvent method is called
after every append. If the value returned from IsTriggeringEvent is
true the contents of the buffer are flushed. 

Here's untested code for an evaluator that should look at the total
length of all messages being buffered to determine whether or not to
issue a flush:

// untested
public class LengthOfMessagesEvaluator : ITriggeringEventEvaluator
{

 private int lengthOfMessages = 0;
 private int threshold = 0;

 public bool IsTriggeringEvent(LoggingEvent loggingEvent)
 {
  if (threshold > 0)
  {
   lengthOfMessages += loggingEvent.RenderedMessage.Length;
   if (lengthOfMessages >= threshold)
   {
    lengthOfMessages = 0;
    return true;
   }
  }
  return false;  
 }

 public int Threshold
 {
  get { return threshold; }
  set { threshold = value; }
 }

}

<!-- untested -->
<evaluator 
  type="Company.Logging.LengthOfMessagesEvaluator, Company.Logging">
 <!-- flush buffer when messages equal ~5mb -->
 <threshold value="5000000"/>
</evaluator>

Let me know if that works.

Thanks,
Ron

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

> Sorry bout that. Didn't mean to hijack Daniel's thread. He had a note
> on
> BufferingForwardingAppender in his thread, which is why I wanted to
> find
> more info on it. 
> 
> My question is this: Currently in the BufferingForwardingAppender,
> the
> number of messages to be buffered can be set using bufferSize. Is
> there
> any way to carry out the buffering based on the size of the messages?
>  
> Thanks,
> Meera.
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
> Sent: Tuesday, April 11, 2006 5:32 PM
> To: Log4NET User
> Subject: RE: Accessing Appender that was created via config file?
> 
> Please don't hijack someone's thread by asking your own unrelated
> question.
> 
> The BufferingForwardingAppender does what you're asking:
> 
> http://tinyurl.com/j7t9s
>
http://logging.apache.org/log4net/release/config-examples.html#buffering
> forwardingappender
> 
> Have you tried it in your application? Is something not working?
> 
> --- Meera Rajaram <mr...@vitalimages.com> wrote:
> 
> > I am using RollingFileAppender to log messages. Is there a way in
> > which
> > I can cache the messages before writing them out to the file?
> Ideally
> > the cache size would be in the configuration file. When the total
> > size
> > of the messages (I need the writing to be done based on size of all
> > messages and not based on number of cached messages) reaches the
> > cache
> > size, I need the messages to be written to the log file. I am new
> to
> > log4Net so I am not sure if I can use BufferingForwardingAppender
> in
> > some way to achieve this? 
> > 
> > Thanks,
> > Meera.
> > 
> > -----Original Message-----
> > From: Daniel Bachler [mailto:DanyX@gmx.net] 
> > Sent: Tuesday, April 11, 2006 9:37 AM
> > To: log4net-user@logging.apache.org
> > Subject: Accessing Appender that was created via config file?
> > 
> > Hi all,
> > 
> > I am currently in the process of switching my app and a few
> libraries
> > I
> > wrote to log4net. So far everything works fine, but now I am at a
> > point
> > where I need the help of people who have more insight into log4net
> > than
> > me.
> > 
> > I want to accomplish two things: First I want an appender to output
> > to a
> > multiline textbox of my app. I think that this might be easiest by
> > working
> > with an appender similar to FireEventAppender from the examples, or
> > are
> > there other suggested ways to do this(*)? The second thing I want
> to
> > achieve
> > is a little trickier. My old, custom logging framework had a
> function
> > called
> > SetJob(string currentJob) that would output the string given to
> what
> > is
> > called the appenders in log4net, but there would be special
> handling
> > to
> > update a small label in the UI to inform the user of what the app
> is
> > currently doing. I thought that the best way to get a similar
> > behaviour
> > was
> > to log objects of type JobMessage or something to replace
> > SetJob(currentJob), and writing a filter to filter based on type
> and
> > an
> > appender that would write this info to the UI. Again, it seems that
> > something along the lines of FireEventAppender would be the easiest
> > way
> > to
> > do this.
> > 
> > This brings me to the core question: FireEventAppender is
> implemented
> > as
> > a
> > weird kind of singleton. Implementing something like
> > FireEventAppender
> > as a
> > singleton would of course be possible, but then I could only have 1
> > and
> > would have to do the filtering (directing most output to the
> > multiline
> > textbox and some to the Current Job UI Label) myself. It seems to
> me
> > that
> > this is not entirely in the spirit of log4net, which is why I
> > (finally)
> > ask:
> > Is there a possibility to get the reference to a certain Appender
> > that
> > was
> > created via config file magic? Something similar to
> > LogManager.GetLogger(),
> > along the lines of LogManager.GetAppenderByName(string name)? If it
> > isn't,
> > do you have any suggestions on how to implement the behaviour
> > described
> > above?
> > 
> > TIA,
> > Daniel
> > 
> > *) As a sidenote: Since some of my function can output a lot of
> > messages
> > within a short amount of time that I want to appear in the
> multiline
> > textbox, I implemented a mechanism to store the messages in memory
> > and
> > append them to the multiline textbox via a timer event. The log4net
> > BufferingForwardingAppender seems to be an alternative to this
> > technique,
> > but as far as I understand it there is no way to get the current
> > implementation to output either every n seconds or whenever the
> > buffer
> > is
> > full, whichever comes first. Is this correct? Is there an
> > implementation
> > that does it this way maybe?
> > 
> > --
> > Daniel Bachler
> > http://www.danyx.com
> > Contact details: http://www.danyx.com/contact
> > The attatched file starting with ATT is a signature for this
> message.
> > To
> > understand how you can verify my identity based on this signature,
> > please go
> > to http://www.danyx.com/WhyGPG
> > 
> > 
> 
> 
>
________________________________________________________________________
> 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
>
________________________________________________________________________
>