我在我的 .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"] 日志吗?非常感谢