【发布时间】:2021-04-13 11:55:21
【问题描述】:
我已在我的 .Net Core 5.0 应用程序中配置 EventLog 以将应用程序事件记录到自定义事件日志:
public Startup (IConfiguration configuration)
{
this.configuration = configuration;
this.logger = LoggerFactory.Create(logging=>{
logging.AddConsole();
logging.AddEventLog(settings=> {
settings.LogName = configuration["EventLogName"];
settings.SourceName = configuration["EventLogSourceName"];
settings.Filter = (category, level) => level >= LogLevel.Trace;
});
}).CreateLogger("Stage server logger");
}
我在 appsettings 中的日志配置:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"EventLog": {
"LogLevel": {
"Default": "Information"
}
}
}
一切正常,但一些消息(尤其是未处理的异常)被写入“应用程序”日志而不是配置 [“EventLogName”] 日志。知道如何配置应用程序以将应用程序中的所有消息记录到 configuration["EventLogName"] 日志吗? 非常感谢
【问题讨论】: