You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Günter Bögel <gb...@hotmail.com> on 2014/04/16 15:47:51 UTC

RE: Flush on idle (BufferingForwardingAppender)

Hi,
 
would be nice if the BufferingForwardingAppender could be configured to flush during idle times. So how about adding:
 
        private int m_flushOnIdle;
        private DateTime m_lastAppendTime=DateTime.Now;
 
        virtual public int FlushOnIdle
        {
            get { return m_flushOnIdle; }
            set
            {
                m_flushOnIdle = value;
                if (m_flushOnIdle==0) return;
                new Thread(() =>
                {
                    while (m_flushOnIdle>0) {
                        Thread.Sleep(m_flushOnIdle/2);
                        if (DateTime.Now - m_lastAppendTime > new TimeSpan(0, 0, 0, 0, m_flushOnIdle))
                            Flush();
                    }
                }){IsBackground = true}.Start();
            }
        }
 
And: 
 
    override protected void Append(LoggingEvent loggingEvent)
    {
        m_lastAppendTime = DateTime.Now;
        ........
 
Regards,
Günter