tags:

views:

1299

answers:

4

I have an application with a String variable that repeated gets a Date from a database, does something with that field, then goes onto the next row.

Is there a way I can send send out some debugging information to the stdout console so I can debug better/view the progress of the program?

+2  A: 

You can use Debug.WriteLine.

You can configure your application to use the ConsoleTraceListener:

To direct all trace and debug messages to the console while the application executes, add a ConsoleTraceListener object to the application configuration file. Edit the configuration file that corresponds to the name of your application, or the app.config file in a Visual Studio 2005 project. In this file, insert an element for a ConsoleTraceListener.

The following example adds a ConsoleTraceListener object named configConsoleListener to the Listeners collection.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="configConsoleListener" 
          type="System.Diagnostics.ConsoleTraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>
 </configuration>

Then you can call Debug.WriteLine and it will log to the output console.

Andrew Hare
30 seconds too slow!
Randolpho
A: 

Try Debug.Writeline()

Randolpho
+1  A: 

A better option is to send it to the Debugger output window. This will be visible while debugging the program and compiled out in a Release build.

Debug.WriteLine("some message")

Calls to Console.WriteLine will fail for a WinForms project. Off the top of my head I can't remember if it will throw or fail silently, but it certainly won't work.

JaredPar
A: 

System.Console.WriteLine will also do the trick.

Documentation

Adam
Won't work in a WinForms project.
JaredPar