Skip to content

Enabling C# debugger logging

Gregg Miskelly edited this page Dec 12, 2019 · 16 revisions

Here is how to enable additional logging for the VS Code C# debugger to help troubleshoot problems.

Quick Method

The quick way to enable logging is to modify your .vscode/launch.json file and add a new 'logging' entry into your active configuration. This works in all cases except problems that happen very early in the initialization stage of the debugger. Here is an example of the new sections to add to launch.json:

"configurations": [
    {
        "...": "...",
        "logging": {
            "engineLogging": true
        }
    },
    { "...": "..." }
]

When this is enabled, logging will be sent to the VS Code Debug Console where you can copy/paste the relevant sections.

Quick Method for Unit tests

Unit tests are not debugged using launch.json, so instead of editing that file, the settings.json file needs to be changed.

To do so, open the command palette (View->Command Palette) and execute 'Preferences: Open Settings (JSON)'. This should open up a json file containing your user options. Add the following option:

   "csharp.unitTestDebuggingOptions": {
        "logging": {
            "engineLogging": true
        }
    }

Full Method

If you are dealing with a problem that happens either very early on during debugger startup, or a problem where the debugger is crashing, it can be helpful to run the debugger (vsdbg-ui) in the console.

To do this:

  1. Open up a terminal (command prompt) window
  2. Change to the directory of the debugger. (NOTE: if you are using VS Code Insiders, change .vscode to .vscode-insiders)
    • Linux/macOS: cd ~/.vscode/extensions/ms-vscode.csharp-<insert-version-here>/.debugger
    • Windows: cd /d C:\Users\<your-username>\.vscode\extensions\ms-vscode.csharp-<insert-version-here>\.debugger
  3. Run vsdbg-ui: ./vsdbg-ui --server --consoleLogging
  4. Go back to VS Code and open your .vscode\launch.json file.
  5. Go to the section for of launch.json for your current launch configuration and add: "debugServer": 4711
  6. Debug as normal
  7. When the problem happens, look at what is printed into the terminal.

Example launch.json configuration:

{
   "version": "0.2.0",
   "configurations": [
        {
            "debugServer": 4711,
            "name": ".NET Core Launch (console)",
            "...": "...",
        },
        { "...": "..." }
    ]
}
Clone this wiki locally