Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See VSTO console output without using a console application

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?

like image 248
tbaker818 Avatar asked Nov 25 '15 23:11

tbaker818


People also ask

How do I show console Output?

IDE used is visual studio 2019. static void Main(string[] args) { int x; int y; Console. WriteLine("Enter the first value"); x = Convert.

How do I show console Output in Visual Studio?

Press F11 . Visual Studio calls the Console.

How do I view console Output in Visual Studio 2010?

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.


1 Answers

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);
like image 194
nouknouk Avatar answered Sep 22 '22 01:09

nouknouk