in src/log4net/Appender/BufferingAppenderSkeleton.cs [384:457]
protected override void Append(LoggingEvent loggingEvent)
{
loggingEvent.EnsureNotNull();
// If the buffer size is set to 1 or less then the buffer will be
// sent immediately because there is not enough space in the buffer
// to buffer up more than 1 event. Therefore as a special case
// we don't use the buffer at all.
if (_cyclicBuffer is null || BufferSize <= 1)
{
// Only send the event if we are in non-lossy mode or the event is a triggering event
if ((!Lossy) ||
(Evaluator is not null && Evaluator.IsTriggeringEvent(loggingEvent)) ||
(LossyEvaluator is not null && LossyEvaluator.IsTriggeringEvent(loggingEvent)))
{
if (_eventMustBeFixed)
{
// Derive class expects fixed events
loggingEvent.Fix = Fix;
}
// Not buffering events, send immediately
SendBuffer([loggingEvent]);
}
}
else
{
// Because we are caching the LoggingEvent beyond the
// lifetime of the Append() method we must fix any
// volatile data in the event.
loggingEvent.Fix = Fix;
// Add to the buffer, returns the event discarded from the buffer if there is no space remaining after the append
LoggingEvent? discardedLoggingEvent = _cyclicBuffer.Append(loggingEvent);
if (discardedLoggingEvent is not null)
{
// Buffer is full and has had to discard an event
if (!Lossy)
{
// Not lossy, must send all events
SendFromBuffer(discardedLoggingEvent, _cyclicBuffer);
}
else
{
// Check if the discarded event should not be logged
if (LossyEvaluator is null || !LossyEvaluator.IsTriggeringEvent(discardedLoggingEvent))
{
// Clear the discarded event as we should not forward it
discardedLoggingEvent = null;
}
// Check if the event should trigger the whole buffer to be sent
if (Evaluator is not null && Evaluator.IsTriggeringEvent(loggingEvent))
{
SendFromBuffer(discardedLoggingEvent, _cyclicBuffer);
}
else if (discardedLoggingEvent is not null)
{
// Just send the discarded event
SendBuffer([discardedLoggingEvent]);
}
}
}
else
{
// Buffer is not yet full
// Check if the event should trigger the whole buffer to be sent
if (Evaluator is not null && Evaluator.IsTriggeringEvent(loggingEvent))
{
SendFromBuffer(null, _cyclicBuffer);
}
}
}
}