I wrote a DLL file that does some database work, and have tested / used with a winforms app, and was sending important debug messages through Console.WriteLine("xxx");
. Now I'm using the DLL in another project that is a Console Application - I'm sure you can imagine my surprise to see all the extra output in the console! Long story short, I need to be able to see debug output in the 'Output' section in Visual Studio, but not in my console. I have looked into this and have changed code around to use Debug.Write("xxx");
and testing with开发者_StackOverflow the code below, however I need to know what to replace System.Console.Out
with to achive the desired reports.
TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(myWriter);
Debug.Write("Important Message");
Thanks -- Andrew
TL;DR; Need to output to VS 'Output' window, not console or file.
By default, there is a trace listener for the VS output window when debugging. You can check this by breaking anywhere in your code and checking the content of: Debug.Listeners. There will be at least 1 entry namely [0] = {System.Diagnostics.DefaultTraceListener} which writes to your VS output window.
So the only thing you neeed to do is remove the registration of your own listener to prevent the output to the console window
精彩评论