首页 > 解决方案 > Serilog Selflog 仅将异常数据写入文件一次

问题描述

我正在使用 asp.net MVC 应用程序。在我的应用程序中,我需要获取 serilog 的内部异常数据。Serilog 提供从以下代码获取异常数据:

Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
HiTrustLog.HiTrustLogger.Information(log);
Serilog.Debugging.SelfLog.Disable();

Serilog 库只写入文件异常数据一次,然后第二次不写入。只是,当内部异常发生时,我需要它写入异常数据

标签: serilogserilog-exceptions

解决方案


ILogger 在全局 asax.cs 中只创建了一次问题。所以,selflog 会写一次日志。在创建 Ilogger 之前触发日志事件时,它可以正常工作


推荐阅读