Reputation: 1991
New to c# and .net, working in visual studio 2012. I want to have the ability to display values to an output window for debug purposes. I am very familiar with the watch windows, but that does not meet my current needs.
My most recent effort I took the exact sample from the msdn website.
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
Debug.AutoFlush = true;
Debug.Indent();
Debug.WriteLine("Entering Main");
Console.WriteLine("Hello World.");
Debug.WriteLine("Exiting Main");
Debug.Unindent();
This example can be found at http://msdn.microsoft.com/en-us/library/system.diagnostics.debug%28v=vs.71%29.aspx
I added a breakpoint on the very next line after the above code. When I hit the breakpoint I have no errors displaying and my output window has none of the anticipated content. I do have the using System.Diagnostics set.
Upvotes: 2
Views: 1989
Reputation: 1745
As described in MSDN, System.Diagnostics.Debug writes their messages into all subscribed TraceListeners (http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener.aspx). Note that you should #define TRACE
or add /d:TRACE when you compile your program. You can setup your listeners in configuration file like this.
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Upvotes: 3