I've been trying to step through example code that I've found and much of it uses Console.WriteLine which doesn't seem to work unless I start over with a new console application. How can I make this work in an existing application that wasn't initially set up a as a console app?
IDE used is visual studio 2019. static void Main(string[] args) { int x; int y; Console. WriteLine("Enter the first value"); x = Convert.
Press F11 . Visual Studio calls the Console.
In Visual Studio 2010, on the menu bar, click Debug -> Windows -> Output. Now, at the bottom of the screen docked next to your error list, there should be an output tab. Click it and double check it's showing output from the debug stream on the dropdown list.
In a VSTO application, you likely have an app which is not a "console enabled" application. And if there is not console window in your application, then by default the strings you write using Console.WriteLine()
are simply discarded.
You should use another function: Debug.WriteLine()
, instead of Console.WriteLine
. That way, the output will be available in your Visual Studio environment (when application is ran in 'debug' mode):
either in the "immediate window" tab (Visual Studio => Menu Debug => Windows => Immediate)
or in the "output" tab, when you choose "Debug" in the combobox "Show output from" (Visual Studio => Menu View => Other Windows => Output)
If you absolutely need to use Console.WriteLine()
(because for example this is used by a third party lib of your project), you can override the default output of this function with Console.SetOut
, which accepts a StreamWriter as parameter. For example, to output the logs in a file, you can put in application startup:
logFile = new System.IO.StreamWriter("C:/myLogs.txt");
Console.SetOut(logFile);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With