Search code examples
c#.net-corequartz.netserilog

Quartz.Net Reduce Logging / Remove Specific Message Serilog


My .NET Core 3 implementation of Quartz.Net is logging the following message approximately twice per minute and I would like to remove it without affecting my applications other logs:

"Batch acquisition of 0 triggers"

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

Where [MyApplication] is populated by the Source property and [Quartz.Core.QuartzSchedulerThread] comes from the SourceContext.

Quartz.net logs this automatically and I seem to have no control over deciding to log it or not. My logs are filling up too quickly.

My Appsettings.json file is as follows:

"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}"
          }
        }
      ]
    }
  }
]

}

My Program.cs main initially configures the logger like this:

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();

And later in my Startup.cs, when my services & settings have been registered Serilog is reconfigured as follows:

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

Where the Reconfigure extension method comes from a 3rd party dll built in another development department.

I have tried to add the following after the invocation of Reconfigure:

SerilogLogger.RefineConfiguration(x => x.MinimumLevel.Override("Quartz", LogEventLevel.Warning));

But it doesn't work because the actual source is MyApplication, and if I use "MyApplication" instead of "Quartz" I suppress all debug and information logs for the entire application.

Any ideas? With code examples please.


Solution

  • I have implemented a solution for this problem, there were two parts to the solution:

    1 - As pointed out to me in the Quartz google groups, I was missing the following Serilog configuration from appsettings.json to define the correct logging level for Quartz:

    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning",
        "Quartz": "Warning"
      }
    },
    

    The configuration of "Quartz": "Warning" suppressed the Debug "Batch acquisition" messages from being logged.

    And

    2 - The invocation of both the SerilogLogger.Reconfigure and SerilogLogger.RefineConfiguration methods was completely unnecessary. I removed this. It was overwriting the config from point 1) above. All Serilog configuration should take place in my appsettings.