Console.WriteLine does not show up in Output window
Solution 1:
Console
outputs to the console window and Winforms applications do not show the console window. You should be able to use System.Diagnostics.Debug.WriteLine
to send output to the output window in your IDE.
Edit: In regards to the problem, have you verified your mainForm_Load
is actually being called? You could place a breakpoint at the beginning of mainForm_Load
to see. If it is not being called, I suspect that mainForm_Load
is not hooked up to the Load
event.
Also, it is more efficient and generally better to override On{EventName}
instead of subscribing to {EventName}
from within derived classes (in your case overriding OnLoad
instead of Load
).
Solution 2:
If you intend to use this output in production, then use the Trace class members. This makes the code portable, you can wire up different types of listeners and output to the console window, debug window, log file, or whatever else you like.
If this is just some temporary debugging code that you're using to verify that certain code is being executed or has the correct values, then use the Debug class as Zach suggests.
If you absolutely must use the console, then you can attach a console in the program's Main
method.
Solution 3:
If you want Console.WriteLine("example text")
output to show up in the Debug Output window, temporarily change the Output type of your Application from Console Application to Windows Application.
From menus choose Project + Properties, and navigate to Output type: drop down, change to Windows Application then run your application
Of course you should change it back for building a console application intended to run outside of the IDE.
(tested with Visual Studio 2008 and 2010, expect it should work in latter versions too)
Solution 4:
Using Console.WriteLine( "Test" );
is able to write log messages to the Output Window (View Menu --> Output) in Visual Studio for a Windows Forms/WPF project.
However, I encountered a case where it was not working and only System.Diagnostics.Debug.WriteLine( "Test" );
was working. I restarted Visual Studio and Console.WriteLine()
started working again. Seems to be a Visual Studio bug.