【问题标题】:Lower log level for QuartzQuartz 的较低日志级别
【发布时间】:2018-11-28 08:34:01
【问题描述】:

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

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

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)。但是,我确实不希望外部库继承我的代码的日志级别。如何做到这一点?

我设法在我的 Serilog 配置中使用 .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)source Microsoft 做到了这一点。但是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 消息吗?

【问题讨论】:

    标签: quartz.net serilog graylog


    【解决方案1】:

    我通过将这一行添加到我的 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();
    

    【讨论】:

    • 谢谢我的日志文件又免费了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    相关资源
    最近更新 更多