根据documentation ,当应用程序关闭时,建议使用以下任一方式处理 Serilog
Log.CloseAndFlush();
或者如果您有
.CreateLogger()
的实例变量,称其.Dispose();
在 Visual Studio 中构建 ASP.NET Core 应用程序时,它会生成
Program
和 Startup
类,它们都没有实现 IDisposable
.我们是否应该将此接口(interface)添加到 Program
这样我们就有办法直接处理 Serilog 了?
最佳答案
据我所知,ASP.NET calls into dispose记录器提供者的责任,因此各个提供者有责任进行任何清理。
但看起来 Serilog 的记录器提供程序在其 dispose 方法中没有做任何事情:
https://github.com/serilog/serilog-extensions-logging/blob/master/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs
我建议在 Serilog 的 repo 上发布一个问题。
关于asp.net-core - 如何在 ASP.NET Core 应用程序中正确处理 Serilog 2.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38286140/