cjbhaines / Log4Net.Async

Asynchronous Log4Net appenders and forwarder
http://www.nuget.org/packages/Log4Net.Async/
MIT License
121 stars 37 forks source link

ParallelForwardingAppender: subscriber task was canceled before completion #29

Closed lbras closed 7 years ago

lbras commented 7 years ago

Hi,

I'm getting this error in an ASP.NET application every time the application pool is recycled:

[ERROR] [BrokerAsynchronousForwarder ParallelForwardingAppender Subscriber Task] [ParallelForwardingAppender] Subscriber task was canceled before completion. System.OperationCanceledException: The operation was canceled. at System.Collections.Concurrent.BlockingCollection1.TryTakeWithNoTimeValidation(T& item, Int32 millisecondsTimeout, CancellationToken cancellationToken, CancellationTokenSource combinedTokenSource) at System.Collections.Concurrent.BlockingCollection1.d__68.MoveNext() at Log4Net.Async.ParallelForwardingAppender.SubscriberLoop()

I'm using the ParallelForwardingAppender together with a lossy BufferingForwardingAppender. If I understand correctly, the BufferingForwardingAppender is flushed on shutdown, forwarding the buffered log requests to the ParallelForwardingAppender, but since the task is canceled the OperationCanceledException is thrown.

Is there a better way to handle this situation or should I just ignore the error?

rcollette commented 7 years ago

Are you calling LogManager.Shutdown() on Application_End? If the logger you are using does not flush within the timeout period, you may still see the above message.

Djiu13 commented 7 years ago

Hi,

I had the same issue. I won't explain in details but I think the last change has introduced the issue. An immediate shutdown was added but there is a delay before SubscriberLoop ends. I have created a pull request and update the code to wait 100ms before entering in the "wait" loop. If someone can review? Hope it will help. @rcollette @cjbhaines

rcollette commented 7 years ago

Closing since this was resolved by the linked PR.