3

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?

2
  • You could use builder.Logging.ClearProviders(); which will remove all loggin with project. Commented Mar 16, 2023 at 11:14
  • @MdFaridUddinKiron I tried that, but still shows the startup message Commented Mar 16, 2023 at 11:17

2 Answers 2

4

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).

Sign up to request clarification or add additional context in comments.

Comments

3

The way to clear logger providers is via:

builder.Logging.ClearProviders();

Disabling logging via configuration is also a valid alternative.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.