private void RequestQueue_BufferOverflowed(AsyncTargetWrapperOverflowAction action, int limit, int count, AsyncLogEventInfo e) { if (BufferOverflowed != null) { BufferOverflowed.Invoke(action, limit, count, e); } }
/// <summary> /// Enqueues another item. If the queue is overflown the appropriate /// action is taken as specified by <see cref="OnOverflow"/>. /// </summary> /// <param name="logEventInfo">The log event info.</param> /// <returns>Queue was empty before enqueue</returns> public bool Enqueue(AsyncLogEventInfo logEventInfo) { lock (this) { if (this.logEventInfoQueue.Count >= this.RequestLimit) { InternalLogger.Debug("Async queue is full"); switch (this.OnOverflow) { case AsyncTargetWrapperOverflowAction.Discard: InternalLogger.Debug("Discarding one element from queue"); var dequeued = this.logEventInfoQueue.Dequeue(); if (BufferOverflowed != null) { BufferOverflowed.Invoke(this.OnOverflow, this.RequestLimit, this.logEventInfoQueue.Count, dequeued); } break; case AsyncTargetWrapperOverflowAction.Grow: InternalLogger.Debug("The overflow action is Grow, adding element anyway"); if (BufferOverflowed != null) { BufferOverflowed.Invoke(this.OnOverflow, this.RequestLimit, this.logEventInfoQueue.Count, logEventInfo); } break; case AsyncTargetWrapperOverflowAction.Block: while (this.logEventInfoQueue.Count >= this.RequestLimit) { InternalLogger.Debug("Blocking because the overflow action is Block..."); if (BufferOverflowed != null) { BufferOverflowed.Invoke(this.OnOverflow, this.RequestLimit, this.logEventInfoQueue.Count, logEventInfo); } System.Threading.Monitor.Wait(this); InternalLogger.Trace("Entered critical section."); } InternalLogger.Trace("Limit ok."); break; } } this.logEventInfoQueue.Enqueue(logEventInfo); return(this.logEventInfoQueue.Count == 1); } }