Filtering log messages

Different execution modes of your application can require different levels of logging. For example, in development mode, you might want to see log events from all application areas, no matter what level they are from. While in production, you probably want to see only log events with warnings and errors that are produced by your application logic, and not from the ASP.NET infrastructure. Luckily, the ASP.NET logging framework makes it very easy to configure a filter with the application settings file.

To set the minimum level of the log messages you allow, open the appsettings.json file and add the Logging element, like this:

{  ...  "Logging": {       "LogLevel": {      "Default": "Warning"    }  }}

In the preceding example, we set ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.