Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 2.85 KB

logging.md

File metadata and controls

84 lines (62 loc) · 2.85 KB

.NET Logging

In vs code, logs from the debug provider and the console provider both show up in the debug console. This ends up duplicating all the logs, and since they're in different formats, makes it really difficult to read and understand.

To make things worse they're not in color. Lame 🙄.

debug_console_log

Reduce the noise

Since the console provider already logs to the debug console, I tend to just turn the debug provider off:

// appsettings.Development.json
{
  "Logging": {
    ...
    "Debug": {
      "LogLevel": {
+       "LogLevel": "None"
      }
    }
  }
}

console_log

And we get much less! ...exactly half as much 🤓

Add some color

So... how bout color? Color would make it a hell of a lot easier to find that error I decided to log earlier (instead of fix), and I recently just so happen to come across this little gem 😍

"DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION": "true"

console_log_allow_ansi

It can be set in your launchSettings.json or vscode launch.json files.

Tip

Add it to your global launch.json and forget it

Single line

Finally, if you're the type that selects compact mode in for your Teams and email threads, we've got something for you too:

// appsettings.Development.json
{
  "Logging": {
    "Console": {
      ...
+     "FormatterOptions": {
+       "SingleLine": true
+     }
    }
  }
}

console_log_allow_ansi_single_line

Other settings

I've found that a couple more settings will reduce the noise in your logs when developing locally:

//.vscode/settings.json
{
  "csharp.debug.logging.moduleLoad": false,
  "csharp.debug.logging.exceptions": false
}