mattwcole / gelf-extensions-logging

GELF provider for Microsoft.Extensions.Logging
MIT License
109 stars 42 forks source link

No way to determine if all logs sent, logs may be lost #41

Closed Silic0nS0ldier closed 5 years ago

Silic0nS0ldier commented 5 years ago

Currently there is no way to determine if all queued log entries have been sent, and as a consequence when a logs may potentially be lost.

This can present a problem in scenarios where an web app has entered an unrecoverable state and can only perform a controlled crash. Or in the case where I discovered this issue, in a short lived console app.

There are 2 ways I can see this limitation being overcome.

  1. Add a new method to check if queue is empty/wait for queue to empty
  2. Add support for dumping logs somewhere, such that they can be reprocessed when the app is running again

Main difference across both would be how quick to close when there is a backlog.

mattwcole commented 5 years ago

Hi, the logger provider waits for all queued messages to be sent when it is diposed (GelfLoggerProvider.Dispose() calls GelfMessageProcessor.Stop()). To ensure this happens on shutdown when using .NET Core dependency injection, you need to make sure the service provider is disposed of like in the (sample console app)

Silic0nS0ldier commented 5 years ago

Thanks for the switch response, Dispose didn't even cross my mind. Adding it in seems to do the trick (there is a slight delay which indicates that something is happening), however I can't say for sure. It would seem I broke something since I last had it in a working state, much to my frustration.

Anyway, concern has been allayed, so closing.