/// <summary> /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)" /> method. /// </summary> /// <param name="loggingEvent">the event to log</param> /// <remarks> /// <para> /// Stores the <paramref name="loggingEvent" /> in the cyclic buffer. /// </para> /// <para> /// The buffer will be sent (i.e. passed to the <see cref="M:log4net.Appender.BufferingAppenderSkeleton.SendBuffer(log4net.Core.LoggingEvent[])" /> /// method) if one of the following conditions is met: /// </para> /// <list type="bullet"> /// <item> /// <description>The cyclic buffer is full and this appender is /// marked as not lossy (see <see cref="P:log4net.Appender.BufferingAppenderSkeleton.Lossy" />)</description> /// </item> /// <item> /// <description>An <see cref="P:log4net.Appender.BufferingAppenderSkeleton.Evaluator" /> is set and /// it is triggered for the <paramref name="loggingEvent" /> /// specified.</description> /// </item> /// </list> /// <para> /// Before the event is stored in the buffer it is fixed /// (see <see cref="M:LoggingEvent.FixVolatileData(FixFlags)" />) to ensure that /// any data referenced by the event will be valid when the buffer /// is processed. /// </para> /// </remarks> protected override void Append(LoggingEvent loggingEvent) { if (m_cb == null || m_bufferSize <= 1) { if (!m_lossy || (m_evaluator != null && m_evaluator.IsTriggeringEvent(loggingEvent)) || (m_lossyEvaluator != null && m_lossyEvaluator.IsTriggeringEvent(loggingEvent))) { if (m_eventMustBeFixed) { loggingEvent.Fix = Fix; } SendBuffer(new LoggingEvent[1] { loggingEvent }); } return; } loggingEvent.Fix = Fix; LoggingEvent loggingEvent2 = m_cb.Append(loggingEvent); if (loggingEvent2 != null) { if (!m_lossy) { SendFromBuffer(loggingEvent2, m_cb); return; } if (m_lossyEvaluator == null || !m_lossyEvaluator.IsTriggeringEvent(loggingEvent2)) { loggingEvent2 = null; } if (m_evaluator != null && m_evaluator.IsTriggeringEvent(loggingEvent)) { SendFromBuffer(loggingEvent2, m_cb); } else if (loggingEvent2 != null) { SendBuffer(new LoggingEvent[1] { loggingEvent2 }); } } else if (m_evaluator != null && m_evaluator.IsTriggeringEvent(loggingEvent)) { SendFromBuffer(null, m_cb); } }
/// <summary> /// Flush the currently buffered events /// </summary> /// <param name="flushLossyBuffer">set to <c>true</c> to flush the buffer of lossy events</param> /// <remarks> /// <para> /// Flushes events that have been buffered. If <paramref name="flushLossyBuffer" /> is /// <c>false</c> then events will only be flushed if this buffer is non-lossy mode. /// </para> /// <para> /// If the appender is buffering in <see cref="P:log4net.Appender.BufferingAppenderSkeleton.Lossy" /> mode then the contents /// of the buffer will only be flushed if <paramref name="flushLossyBuffer" /> is <c>true</c>. /// In this case the contents of the buffer will be tested against the /// <see cref="P:log4net.Appender.BufferingAppenderSkeleton.LossyEvaluator" /> and if triggering will be output. All other buffered /// events will be discarded. /// </para> /// <para> /// If <paramref name="flushLossyBuffer" /> is <c>true</c> then the buffer will always /// be emptied by calling this method. /// </para> /// </remarks> public virtual void Flush(bool flushLossyBuffer) { lock (this) { if (m_cb != null && m_cb.Length > 0) { if (m_lossy) { if (flushLossyBuffer) { if (m_lossyEvaluator != null) { LoggingEvent[] array = m_cb.PopAll(); ArrayList arrayList = new ArrayList(array.Length); LoggingEvent[] array2 = array; foreach (LoggingEvent loggingEvent in array2) { if (m_lossyEvaluator.IsTriggeringEvent(loggingEvent)) { arrayList.Add(loggingEvent); } } if (arrayList.Count > 0) { SendBuffer((LoggingEvent[])arrayList.ToArray(typeof(LoggingEvent))); } } else { m_cb.Clear(); } } } else { SendFromBuffer(null, m_cb); } } } }