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.

Flush on shutdown

See original GitHub issue

Other logging frameworks have different ways of telling the framework that the application is about to shut down. This is great for batching and/or async loggers since it will give them a chance to flush their buffered log message.

Example from Serilog:

Log.CloseAndFlush();

Example from NLog:

LogManager.Shutdown();

I cannot seem to find a similar feature of Microsoft.Extensions.Logging. I know that providers indirectly implement IDisposable but Dispose doesn’t seem to be consistently called on shutdown.

Is there any way of detecting that an application is about to shut down or would it be possible to implement support for this in Microsoft.Extensions.Logging?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davidfowlcommented, Sep 26, 2019

Yep 😄 !

0reactions
ThomasArdalcommented, Sep 26, 2019

That’s a good point 😂 I guess this would be the way to go?

var services = new ServiceCollection();
services.AddLogging(logging => logging.AddBlaBla(...));
var serviceProvider = services.BuildServiceProvider();
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger("mylogger");
// Do some logging
serviceProvider.Dispose();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Flushing buffered data at shutdown #1496 - fluent/fluent-bit
I'm trying to replace fluentd to fluent-bit for reducing container size, but fluent-bit seem not to flush data in buffer when shutting down....
Read more >
Do I need to flush events when shutting down using logback?
In the shutdown of our application we currently call: org.apache.log4j.LogManager.shutdown();. Which is supposed to flush all async logging and ...
Read more >
Remember to flush Application Insights on shutdown!
Here is how to ensure that Azure Application Insights logs and performance are not lost on shutdown, all while also optimizing log ...
Read more >
Avoiding File Flush at Server Shutdown
The c‑tree Server flushes files to disk when it is shut down. In the case of a “scratch” or “temp” file, it may...
Read more >
No flush cache on shutdown
So demanding a "no flush" on shutdown seems a little naive to me. If you really want a fast shutdown and still using...
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