asp.net-core - 如何在 ASP.NET Core 应用程序中正确处理 Serilog 2.0?

标签 asp.net-core serilog

根据documentation ,当应用程序关闭时,建议使用以下任一方式处理 Serilog

 Log.CloseAndFlush();

或者如果您有 .CreateLogger() 的实例变量,称其
.Dispose();

在 Visual Studio 中构建 ASP.NET Core 应用程序时,它会生成 ProgramStartup类,它们都没有实现 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/

相关文章:

c# - ActionFilterAttribute 中的 GetService 返回 null

c# - CreateLogger() 之前被调用过,只能调用一次

jenkins - 使用 dotnet Restore 设置 npm 私有(private)注册表

c# - 将 Serilog ILogger 添加到静态类

c# - Serilog 自定义接收器 - 使用 appsettings.json 设置最低级别不起作用

asp.net-core - 如何在自宿主环境中在ASP.NET Core中gzip静态内容

c# - 打包项目时传递运行时依赖被丢弃,导致运行时失败

.net - 哪些文件名占位符可用于 Serilog?

logging - Serilog - 如何为文件接收器自定义解构类对象的输出格式

elasticsearch - "Message"字段不是由 Serilog ElasticSearch 接收器发送