【发布时间】:2020-06-23 13:56:43
【问题描述】:
我的 Quartz.Net 的 .NET Core 3 实现大约每分钟记录两次以下消息,我想删除它而不影响我的应用程序的其他日志:
“批量获取0个触发器”
2020-06-22 17:42:24.745 +01:00 - [MyApplication] - [Debug] - [Quartz.Core.QuartzSchedulerThread] Batch acquisition of 0 triggers
2020-06-22 17:42:53.689 +01:00 - [MyApplication] - [Debug] - [Quartz.Core.QuartzSchedulerThread] Batch acquisition of 0 triggers
其中[MyApplication] 由Source 属性填充,[Quartz.Core.QuartzSchedulerThread] 来自SourceContext。
Quartz.net 会自动记录这一点,我似乎无法决定是否记录它。我的日志填得太快了。
我的Appsettings.json文件如下:
"Serilog": {
"IncludeScopes": false,
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "C:/Logs/my-app.log",
"buffered": "true",
"flushToDiskInterval": "00:00:10",
"rollingInterval": "Infinite",
"rollOnFileSizeLimit": "true",
"fileSizeLimitBytes": 10485760,
"retainedFileCountLimit": 90,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} - {Source} - [{Level}] - [{SourceContext}] {Message}{NewLine}{Exception}"
}
},
{
"Name": "Async",
"Args": {
"restrictedToMinimumLevel": "Information",
"configure": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} - {Source} - [{Level}] - {Message}{NewLine}{Exception}"
}
}
]
}
}
]
}
我的 Program.cs main 最初是这样配置记录器的:
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
// set Source property, which we use in output formatting, to the name of the application
.Enrich.WithProperty("Source", value: "MyApplication")
.CreateLogger();
稍后在我的 Startup.cs 中,当我的服务和设置已注册时,Serilog 重新配置如下:
public void Configure(IApplicationLifetime applicationLifetime)
{
SerilogLogger.Reconfigure(
applicationName: "MyApplication",
toFixedFile: !string.IsNullOrEmpty(_loggerSettings.LogFilePathFixed),
fileName: _loggerSettings.LogFilePathFixed,
fileSizeBytes: configuredLogFileSize * 1024 * 1024,
minimalLevel: "Debug",
outputTemplate: _loggerSettings.LogFormat);
}
Reconfigure 扩展方法来自另一个开发部门构建的第 3 方 dll。
我尝试在调用Reconfigure后添加以下内容:
SerilogLogger.RefineConfiguration(x => x.MinimumLevel.Override("Quartz", LogEventLevel.Warning));
但它不起作用,因为实际来源是MyApplication,如果我使用“MyApplication”而不是“Quartz”,我会禁止整个应用程序的所有调试和信息日志。
有什么想法吗?请提供代码示例。
【问题讨论】:
标签: c# .net-core quartz.net serilog