Display a message in Visual Studio's output window when not debug mode?

Viewed 102527

In Java, you can use System.out.println(message) to print a message to the output window.

What's the equivalent in Visual Studio ?

I know when I'm in debug mode I can use this to see the message in the output window:

Debug.WriteLine("Debug : User_Id = "+Session["User_Id"]);
System.Diagnostics.Trace.WriteLine("Debug : User_Id = "+Session["User_Id"]);

How can this be done without debugging in Visual Studio?

6 Answers

The Trace messages can occur in the output window as well, even if you're not in debug mode. You just have to make sure the the TRACE compiler constant is defined.

The Trace.WriteLine method is a conditionally compiled method. That means that it will only be executed if the TRACE constant is defined when the code is compiled. By default in Visual Studio, TRACE is only defined in DEBUG mode.

Right Click on the Project and Select Properties. Go to the Compile tab. Select Release mode and add TRACE to the defined preprocessor constants. That should fix the issue for you.

Related