1

When debugging a typical ASP.NET Core app with one of the default templates, I am faced with duplicate log lines in the DEBUG CONSOLE, e.g.:

enter image description here

It is extremely annoying because it makes the log difficult to read by constantly switching indentation and with repetitions. I have not configured any logging in Program.cs nor in Startup.cs, so the default configuration is doing this.

Why is it doing this, and can I remove it?

I thought maybe the root cause was because CreateDefaultBuilder(...) adds both debug and console logging. So I tried rolling my own:

            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                //logging.AddDebug();
                logging.AddEventSourceLogger();
            })

But that had no effect.

2
  • As far as I remember, that's the default console log format. The first line is an overview of the log and the following lines is the expanded, detailed version. Switch to Serilog, NLog or your favorite logger if you don't like that format Commented Sep 13, 2020 at 16:37
  • Not correct. The dupicate logs are due to the console logging being directed to the debug console in addition to the debug logging. Commented Oct 5, 2020 at 17:45

1 Answer 1

5

The dupicate logs are due to the

console logging

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001

being directed to the debug console by default in vscode in addition to the

debug logging.

Microsoft.Hosting.Lifetime: Information: Now listening on: https://localhost:5001

You can either separate console logging using launch.json

"console":"integratedTerminal"

Or as you where trying to do remove the debug logging. Note you need to add ClearProviders()

.ConfigureLogging((hostingContext, logging) =>
{
      logging.ClearProviders();
      logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
      logging.AddConsole();
      //logging.AddDebug();
      logging.AddEventSourceLogger();
})

Please also see Remove console and debug loggers in ASP.NET Core 2.0 when in production mode

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

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.