serilog-contrib / serilog-sinks-teams

A Serilog event sink that writes to Microsoft Teams
MIT License
18 stars 11 forks source link

Possible Close and Flush Error #4

Closed SilentBlueD666 closed 6 years ago

SilentBlueD666 commented 6 years ago

Hi, I been using this sink in a console app and have notice that if the application quits before the "Serilog.Sinks.PeriodicBatching" OnTick event has been run then the logs in the queue are lost.

After looking at the "MicrosoftTeamsSink.cs" I believe this maybe due to the order in which things are disposed, in the Dispose() method.

Currently the HttpClient is disposed first then the Base Dispose method is called where it tries to flush the buffer however I would assume this fails because the HttpClient is no longer valid, thus dropping the buffer.

I have tried to SelfLog to test this theory but noting is outputted to the temp file I created, which also leads me to believe that it may not even get to the Dispose method as well.

Any help would be great as really like this sink :)

SilentBlueD666 commented 6 years ago

Update: Was able to get my self logging working correctly, as you can see below this maybe the problem I was talking about.

2018-03-27T12:08:59.9966286Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.<EmitBatchAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.<OnTick>d__16.MoveNext() 2018-03-27T12:09:00.0046354Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.<EmitBatchAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.<OnTick>d__16.MoveNext()

ShareBuilderAustin commented 6 years ago

@SilentBlueD666 , I'm having the same issue on an extremely basic Console Test app: 2018-03-30T15:19:23.4978972Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.d4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.d16.MoveNext() Exception thrown: 'System.ObjectDisposedException' in System.Net.Http.dll Exception thrown: 'System.ObjectDisposedException' in System.Private.CoreLib.dll 2018-03-30T15:19:23.6187443Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.d4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.d16.MoveNext()

SilentBlueD666 commented 6 years ago

I know how to fix it, just need access to submit the change.

Get Outlook for iOShttps://aka.ms/o0ukef


From: ShareBuilderAustin notifications@github.com Sent: Friday, March 30, 2018 4:22:00 PM To: DixonDs/serilog-sinks-teams Cc: Darren; Mention Subject: Re: [DixonDs/serilog-sinks-teams] Possible Close and Flush Error (#4)

@SilentBlueD666https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FSilentBlueD666&data=02%7C01%7C%7C932b6b4a32db471c1e5f08d59651fc8c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636580201223138891&sdata=EEcdiL2aIPDuPoUiatYLfKHwQYAF8kL6j%2BbsBbJRp%2Fg%3D&reserved=0 , I'm having the same issue on an extremely basic Console Test app: 2018-03-30T15:19:23.4978972Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.d4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.d16.MoveNext() Exception thrown: 'System.ObjectDisposedException' in System.Net.Http.dll Exception thrown: 'System.ObjectDisposedException' in System.Private.CoreLib.dll 2018-03-30T15:19:23.6187443Z Exception while emitting periodic batch from Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'. at System.Net.Http.HttpClient.CheckDisposed() at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Serilog.Sinks.MicrosoftTeams.MicrosoftTeamsSink.d4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.d16.MoveNext()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FDixonDs%2Fserilog-sinks-teams%2Fissues%2F4%23issuecomment-377548316&data=02%7C01%7C%7C932b6b4a32db471c1e5f08d59651fc8c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636580201223138891&sdata=wO8nKP4DEBjYLHzuxrc7c8qE07Air%2FYOxfXTnlj3Qyk%3D&reserved=0, or mute the threadhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMm8gOiuhsa1Czv3lj5DoUSrp6N-Celqks5tjk2YgaJpZM4S8t8g&data=02%7C01%7C%7C932b6b4a32db471c1e5f08d59651fc8c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636580201223138891&sdata=hDwsA4JbsSkOJYSWYYXZ%2Flemf75%2B%2BvFaSKbIoHy2jzE%3D&reserved=0.

DixonDs commented 6 years ago

Hi @SilentBlueD666 and @ShareBuilderAustin! The change is now merged and published as 0.2.1: https://www.nuget.org/packages/Serilog.Sinks.MicrosoftTeams/0.2.1