DEV Community

Cover image for Enabling and Disabling Logs in ASP.NET Core 6
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

6

Enabling and Disabling Logs in ASP.NET Core 6

Almost all the .NET 6 (and previous) templates have enabled by default the new logging system.
This is very useful but in a big project, the logs might be too much confusing.
But this logging system is not an on/off system.
You can decide, from the settings, the tracing level for all the libraries and namespaces in the project.

By default, your appsettings.json looks more or less like this one:

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
Enter fullscreen mode Exit fullscreen mode

Customize the logging level by the source it's very easy. You can just add the namespace and the minimum log level:
This is one of my appsettings.json for a real project:

"Logging": {
    "LogLevel": {
      "Default": "Trace",
      "System": "Information",
      "Microsoft": "Information",
      "Microsoft.AspNetCore.Authentication": "Warning",
      "Microsoft.IdentityModel": "Warning"
    }
  },
Enter fullscreen mode Exit fullscreen mode

LogLevel indicates the severity of the log and ranges from 0 to 6:

Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6

When a LogLevel is specified, logging is enabled for messages at the specified level and higher.

Happy Logging!


Thanks for reading this post, I hope you found it interesting!

Feel free to follow me to get notified when new articles are out πŸ™‚

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay