Josh Fischer - .NET and C# Consultant

.NET, C#, Azure, WinUI, Wpf, Uno, Sql, Visual Studio, Webassembly

Visual Studio Output Window Options

- Posted in Visual Studio by

Visual Studio can be a cruel partner. One bad upgrade or one misclick can change the way it operates or what it reports to you. Over the years I have had a few frustrating, head-slapping moments. Recently, one of these moments happened when my Output window "stopped working" and wasn't printing the most basic output messages while debugging. This led me to discover a feature that I never knew about or encountered before.

First, let's explore some of the ways you can write to the Output window in Visual Studio. In the code below, what will be printed?

System.Console.WriteLine("Console.WriteLine");
System.Diagnostics.Debug.WriteLine("Debug.WriteLine");
System.Diagnostics.Debug.Print("Debug.Print");
System.Diagnostics.Trace.WriteLine("Trace.WrieLine");
System.Diagnostics.Debugger.Log(1, "Debugger", "Log");

The answer is...complicated. Line 1 will only print if the application is a Console app and it will only print to the console window. This is very unfortunate because many people use Console apps to demonstrate their code snippets and this can give a new developer a false impression that the "console" is a universal output method.

Lines 2 and 3 will only show for Debug builds or, more specifically, when the DEBUG compilation symbol is used. Line 4 will print for both Debug and Release builds or, again more specifically, any configuration that has the TRACE compilation symbol defined.

Line 5 will only display if a debugger is attached. Since we are assuming the use of Visual Studio in this article, we could say that it will "always" print. However even this very direct and explicit method is not enough to guarantee that your output will display.

As I said above, sometimes I misclick or use the wrong keyboard shortcut in Visual Studio and I don't know what feature I changed. This happened recently and my Output window stopped showing messages of all kinds. It turns out you can control what displays at the UI level in Visual Studio. If you right-click on the Output window there is a "Program Output" option in the menu which controls displaying of the debug messages. I have no idea why this option exists, but when I was using the trackpad on my laptop I somehow managed to disable this without realizing it.

VS Output window context menu

Strangely, this option is no longer available under Options -> Debugging -> Output Window even thought it was when I first encountered the problem.

VS Options