Log entries are lost unless a delay is added at the end of the execution for async Task method
See original GitHub issueHi,
We are loosing our seq logs for the latest part of our execution unless we add a 3 seconds delay at the end of the application.
LiterateConsole
and RollingFile
preserve the logs without needing the delay.
The task is awaited with this style: MyAsyncTask().Wait();
Could you please advise on the issue.
Serilog 2.0.0
Serilog.Sinks.Seq 2.0.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Log entries are lost unless a delay is added at the end of ...
Hi, We are loosing our seq logs for the latest part of our execution unless we add a 3 seconds delay at the...
Read more >c# 4.0 - Async Logger. Can I lose/delay log entries?
So if all threads of the application end, tasks will stop as well, which will cause all 'waiting' log entries to be lost.)...
Read more >Because this call is not awaited, execution of the current ...
Dim delay = 5000 ' Call #1. ' Call an async method. Because you don't await it, its completion isn't ' coordinated with...
Read more >Common async / Task mistakes, and how to avoid them
After the sleep, the Task.Delay(500) starts running, the further execution is deferred, and we return to the Main() method. Now, the second ...
Read more >Bug - async and uncaught Exceptions
If there occur any exceptions that aren't caught and logged manually, they are dropped silently without any logging done by Unity.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
TLDR: call
Dispose()
on your host.I know this is very late but if there is still people (like me) that got here with the same problem and found that the solution proposed using
CloseAndFlush()
by grabbing a reference from staticLog
is unacceptable in some scenarios (in our case we are following DI service composition rules that dictate strictly pass-on-constructor dependencies and discourage static references):I was looking to grab any Seq or Serilog factory disposal handle that I could subscribe to the teardown of the program. But I actually found out upon trying first an explicit call to Host.Dispose() that Seq did a good job event-wiring its own disposal to the contextual disposal process inside the Generic Host. And obviously flushing is part of the disposal.
HTH
Hi @chmirenko,
Since Serilog 2.0’s release, you need to add
Log.CloseAndFlush()
or callDispose()
on the object returned fromLoggerConfiguration.CreateLogger()
to ensure all buffered writes complete before exiting.More details in this blog post by @merbla: http://blog.merbla.com/2016/07/06/serilog-log-closeandflush/
Let me know if this doesn’t cover it. Cheers!