jjchiw / gelf4net

GELF log4net Appender - graylog2
MIT License
63 stars 59 forks source link

Gelf4Net HttpAppender causes InvalidOperationException #50

Closed thisLambo closed 6 years ago

thisLambo commented 7 years ago

My ASP.NET WepAPI application is making use of the HttpAppender for logging.

The issue I am encountering is that on two of my web methods, the calls result in:

[InvalidOperationException]: An asynchronous module or handler completed while an asynchronous operation was still pending.

which is related to this issue: https://stackoverflow.com/questions/15060214/web-api-httpclient-an-asynchronous-module-or-handler-completed-while-an-async

And can be seen here: GelfHttpAppender.cs

The commented out code would possibly resolve the issue since I don't think the AppenderSkeleton supports Append as returning a Task.

thisLambo commented 7 years ago

Closed because I thought the issue was with my code. Wrapped a line of code talking to log4net in a Task.Run() and the issue went away. The issue still exists.

JoshuaPHolden commented 7 years ago

I agree that that Task.Run may correct the issue but this should probably be updated further:

protected override async void Append(LoggingEvent loggingEvent) This should probably be changed to async task so that the async / await manager knows when it is completed.

thisLambo commented 7 years ago

@nezoic A better workaround I found was to use https://github.com/cjbhaines/Log4Net.Async and wrap the HttpAppender with that. It still isn't as nice as having the GelfHttpAppender handle it though.