Console.WriteLine
Output window
troubleshooting
debugging
Visual Studio

Console.WriteLine not showing in the Visual Studio Output window

Codemia Knowledge Hub ·

Console.WriteLine writes to the console, not to Visual Studio's Output window. In a Windows Forms, WPF or ASP.NET application there is no console window, so the text does not appear where you expect. Use System.Diagnostics.Debug.WriteLine to send debug messages to the Output window instead.

Why the output goes missing

  1. The project is not a console application. Windows Forms, WPF and ASP.NET apps do not have a console window by default, so Console.WriteLine output is not shown anywhere obvious.
  2. You are looking in the Output window. Visual Studio's Output window shows debugger output, which is separate from the console. Without the right configuration, console text will not appear there.
  3. Standard output is redirected. Your application's configuration may send standard output to a file or another stream.

Getting the output to show

  • In a console application, Console.WriteLine displays in a console window by default. Check that the project really is set up as a console application.
  • In other application types, redirect the output to a window or a file. A typical approach in Windows applications is to use the debugger output method System.Diagnostics.Debug.WriteLine.
  • You can explicitly set the output stream for diagnostics in configuration files or main execution:
csharp
1using System;
2using System.Diagnostics;
3using System.IO;
4
5// In Main: send Console.WriteLine output to a file
6var writer = new StreamWriter("console.log") { AutoFlush = true };
7Console.SetOut(writer);
8Console.WriteLine("This line goes to console.log");
9
10// Anywhere: in a Debug build, this appears in Visual Studio's Output window while debugging
11Debug.WriteLine("This line goes to the Output window");

Console.SetOut redirects everything later written with Console.WriteLine. Debug.WriteLine calls are compiled only into Debug builds, so they produce nothing in a Release build.


Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms