Lower log level for Quartz
Asked Answered
G

2

6

I am using Serilog in my .NETCore servers with several sinks such as console, file and graylog (GELF) for my cloud deployments.

As soon as I set the log-level to DEBUG I get messages from the quartz scheduler thread every few seconds. How can I turn this OFF? It shows thousands of useless entries like so:

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

I wrote a REST API to dynamically change the log level without restarting the services (see _logLevelSwitch in the config below). However, I do NOT want external libraries to inherit the log level for my code. How can this be done?

I managed to do this for the source Microsoft using .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) in my Serilog configuration. But Quartz is a library and its source is the name of my own binary, so I cannot lower the loglevel in the same way. Here is my Serilog configuration (the general part, other props are set depending on the runtime environment)

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

And then I use additional runtime specific configuration code like:

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;
    .....
}

I read that Quartz.Net is using Commons.logging but I do not use it and I have no configuration for it.

Any idea how to get rid of those Quartz.Core.QuartzSchedulerThread messages?

Geraldgeralda answered 28/11, 2018 at 8:34 Comment(0)
R
4

I solved this problem by adding this line to my Serilog config:

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

So your config would be:

     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();
Roscoe answered 22/8, 2019 at 11:33 Comment(1)
Thank you my log files are free again!Alberto
W
1

This worked for me in .NET Core:

appsettings.json:

"Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Information",
      "Microsoft.Hosting.Lifetime": "Information",
      "Quartz": "Information",
      "Quartz.Core.QuartzSchedulerThread": "Information",
      "Quartz.Core.JobRunShell": "Information"
    }
  },
Wessex answered 21/11, 2022 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.