Where does .NET's Debug.Write() output to?
I didn't see any output in the console or Visual Studio's output panel from:
Debug.Write("WriteStatements(开发者_JAVA百科) was reached")
Where does the output go to?
Zhaph's answer already told you a way to get to the output of Debug.Write
.
Under the hood, the default listener for Debug.Write
, i.e. System.Diagnostics.DefaultTraceListener
, calls the Windows API function OutputDebugString
.
Any message passed to that function can be displayed by a debugger, e.g. you will see the output in the Output window of Visual Studio.
Another quite simple way to see the output of Debug.Write
and/or Trace.Write
is to use DebugView, a tool from Sysinternals:
DebugView is an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don't need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.
Please note, that Debug.Write
statements will not be included in a Release build, hence you would only see the output in the Debug build.
It writes to the default trace listener, which you would need to turn on:
Debug.Write Method
If you want this directed to the console you would need to add an instance of the ConsoleTraceListener:
In your .config file ensure you have the following entries:
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="configConsoleListener"
type="System.Diagnostics.ConsoleTraceListener" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
You may also need to ensure that you've included the /d:TRACE
flag when compiling your project to enable the output.
精彩评论