gpt4 book ai didi

quartz.net - Quartz 的较低日志级别

转载 作者:行者123 更新时间:2023-12-02 02:47:56 34 4
gpt4 key购买 nike

我在我的 .NETCore 服务器中使用 Serilog,并在我的云部署中使用多个接收器,例如控制台、文件和 Graylog (GELF)。

一旦我将日志级别设置为 DEBUG,我每隔几秒钟就会从 quartz 调度程序线程收到消息。我怎样才能关闭它?它显示了数以千计的无用条目,如下所示:

2018-11-27 22:09:35.210 +00:00 [DBG] [Quartz.Core.QuartzSchedulerThread] [ThreadId 5] Batch acquisition of 0 triggers
2018-11-27 22:10:04.038 +00:00 [DBG] [Quartz.Core.QuartzSchedulerThread] [ThreadId 5] Batch acquisition of 0 triggers
2018-11-27 22:10:30.869 +00:00 [DBG] [Quartz.Core.QuartzSchedulerThread] [ThreadId 5] Batch acquisition of 0 triggers
2018-11-27 22:11:00.591 +00:00 [DBG] [Quartz.Core.QuartzSchedulerThread] [ThreadId 5] Batch acquisition of 0 triggers

我编写了一个 REST API 来动态更改日志级别而无需重新启动服务(请参阅下面配置中的 _logLevelSwitch)。但是,我做 不希望外部库继承我代码的日志级别 .如何才能做到这一点?

我设法为 source 做到了这一点微软使用 .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)在我的 Serilog 配置中。但是Quartz是一个库,它的来源是我自己的二进制文件的名称,所以我不能以同样的方式降低日志级别。这是我的Serilog配置(通用部分,其他props根据运行环境设置)

        var loggerConfig = new LoggerConfiguration()
.MinimumLevel.ControlledBy(_logLevelSwitch)
.Enrich.FromLogContext()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.WithProcessName()
.Enrich.WithThreadId()
.Enrich.WithMachineName()
.Enrich.WithAssemblyName();

然后我使用额外的运行时特定的配置代码,如:
switch (po.Runtime)
{
case Runtime.DevelLocal:
loggerConfig.Enrich.WithProperty(new KeyValuePair<string, object>("runtime", CommonConstants.RtDevelLocal));
_logLevelSwitch.MinimumLevel = LogEventLevel.Debug;
loggerConfig.WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] " +
"[ThreadId {ThreadId}] {Message:lj}{NewLine}{Exception}");
loggerConfig.WriteTo.File(Path.Combine(po.LogPath, $"{BbDeConstants.ProductName}-.log"), rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] " +
"[ThreadId {ThreadId}] {Message:lj}{NewLine}{Exception}");
break;
case Runtime.DemoDatacenter:
loggerConfig.Enrich.WithProperty(new KeyValuePair<string, object>("runtime", CommonConstants.RtDemoDatacenter));
loggerConfig.WriteTo.Graylog(new GraylogSinkOptions
{
HostnameOrAddress = po.LogHost,
TransportType = TransportType.Udp,
Port = 12201,
Facility = "BizBus",
});
break;
.....
}

我读到了 Quartz.Net正在使用 Commons.logging但我不使用它,我有 没有它的配置 .

知道如何摆脱那些 Quartz.Core.QuartzSchedulerThread消息?

最佳答案

我通过将这一行添加到我的 Serilog 配置中解决了这个问题:

   .MinimumLevel.Override("Quartz", LogEventLevel.Information)

所以你的配置是:
     var loggerConfig = new LoggerConfiguration()
.MinimumLevel.ControlledBy(_logLevelSwitch)
.Enrich.FromLogContext()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Quartz", LogEventLevel.Information)
.Enrich.WithProcessName()
.Enrich.WithThreadId()
.Enrich.WithMachineName()
.Enrich.WithAssemblyName();

关于quartz.net - Quartz 的较低日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53515182/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com