serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.29k stars 203 forks source link

Invalid/Outdated ASP.NET Core sample #309

Open plachor opened 1 year ago

plachor commented 1 year ago

Hi, in your sample sections there is a template how to setup Serilog with ASP. In this sample you suggest to log clean disposal of host (which would be great to do): https://github.com/serilog/serilog-aspnetcore/blob/dev/samples/Sample/Program.cs#L22

However in case of graceful shutdown you are not guaranteed that this code will ever be executed. Once host completes disposal it will terminate process in parallel most of time not reaching that line of code. In order to make it work every time you would need hook within those extensions methods from ASP or to add your own solution I believe.

Additionally you might update this template to use asynchronous overloads. As main can return Task now.

nblumhardt commented 3 weeks ago

Once host completes disposal it will terminate process in parallel most of time not reaching that line of code.

I haven't observed this - any pointer to where it's documented or implemented? (Is this possibly an issue under IIS or something like that?)