2

Is it possible to remove all logging from the minimal web api? I searched for it and my code currently looks like this:

builder.Services.AddLogging(b => {
    b.ClearProviders();
});

This almost works for everything besides the startup message seen below:

info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: PATH REDACTED

Is it possible to remove this startup message as well?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Marvin
  • 37
  • 1
  • 3

2 Answers2

2

Check appsettings.json files (including environment specific ones) and set values there to None. For example for default ones:

{
  "Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft.AspNetCore": "None"
    }
  }
}

Also check out the logging docs (and ASP.NET Core specific ones, though they should be quite similar).

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
2

The way to clear logger providers is via:

builder.Logging.ClearProviders();

Disabling logging via configuration is also a valid alternative.

davidfowl
  • 37,120
  • 7
  • 93
  • 103