tags:

views:

128

answers:

2

Hi folks:

I didn't see any output in console or VS output panel from

Debug.Write("WriteStatements() was reached")

Where does the output go to?

Thanks.

+5  A: 

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.

Zhaph - Ben Duguid
No default listener?
Ricky
@Ricky There is a DefaultTraceListener (http://msdn.microsoft.com/en-us/library/system.diagnostics.defaulttracelistener.aspx), which will apparently "emit the message to the Win32 OutputDebugString function and to the Debugger.Log method. For information about the OutputDebugString function, see the Platform SDK or MSDN", but you wanted it in the Console/Output window, which needs the ConsoleTraceListener.
Zhaph - Ben Duguid
@Zhaph: Didn't see your comment until I had posted my answer, sorry.
0xA3
@divo - No worries, you make a good point about DebugView picking it up, and also the note about release builds ;)
Zhaph - Ben Duguid
+3  A: 

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.

0xA3