question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log entries are lost unless a delay is added at the end of the execution for async Task method

See original GitHub issue

Hi,

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.

LiterateConsoleand 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mxwlfcommented, Nov 5, 2021

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 static Log 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

  • Wolf
2reactions
nblumhardtcommented, Jul 11, 2016

Hi @chmirenko,

Since Serilog 2.0’s release, you need to add Log.CloseAndFlush() or call Dispose() on the object returned from LoggerConfiguration.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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found