Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different Minimum Level Logs Serilog

Tags:

Is there a way to differentiate what level is logged between the different loggers for Serilog? I want to be able to log MinimumLevel Debug to the console output but only Warning and above to my file output. I am using ASP.NET Core 2.1 and this is what the appsetting.json currently looks like:

"Serilog": {     "Using": [ "Serilog.Sinks.Console" ],     "MinimumLevel": "Debug",     "WriteTo": [       {         "Name": "RollingFile",         "IsJson": true,         "Args": {           "pathFormat": "C:\\Logs\\Log-{Hour}.json",           "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"         }       },       {         "Name": "Console"       }     ]   }, 

Is it something like another parameter under "Args"? I've tried "minimumnLevel" in this location but it did not work.

like image 201
jollyroger23 Avatar asked Aug 27 '18 20:08

jollyroger23


People also ask

What is minimum level in Serilog?

The MinimumLevel configuration object provides for one of the log event levels to be specified as the minimum. In the example above, log events with level Debug and higher will be processed and ultimately written to the console. Verbose is the noisiest level, rarely (if ever) enabled for a production app.

What are the log levels?

Logging levels explained. The most common logging levels include FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL, and OFF. Some of them are important, others less important, while others are meta-considerations.

What is Serilog logging?

Serilog is an easy-to-set-up logging library for . NET with a clear API. In the long list of the Serilog's features you can find: Support of structured logging, which allows logs to be treated as data sets rather than text. Compatibility with asynchronous applications and systems.

What is Serilog and seq?

Serilog is Seq's most supported logging library. Begin logging to Seq by adding the Serilog. Sinks. Seq package. Seq has excellent support for all of Serilog's features including complex event data, enrichment and structured events.


1 Answers

The setting you're looking for is restrictedToMinimumLevel. This GitHub issue shows some examples of this, but for your example, you just need to add restrictedToMinimumLevel to your Args for RollingFile:

"Serilog": {     "Using": [ "Serilog.Sinks.Console" ],     "MinimumLevel": "Debug",     "WriteTo": [       {         "Name": "RollingFile",         "IsJson": true,         "Args": {           "pathFormat": "C:\\Logs\\Log-{Hour}.json",           "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",           "restrictedToMinimumLevel": "Warning"         }       },       {         "Name": "Console"       }     ]   }, 
like image 154
Kirk Larkin Avatar answered Sep 22 '22 23:09

Kirk Larkin