Saturday, January 23, 2016

Difference Between Debug & Trace

Difference Between Debug & Trace

Trace works in both Debug as well as Release mode.

Code written in Debug mode and its output:

Same code, as above, written in Release mode and its output:

The main advantage of using Trace over Debug is to do performance analysis which can not be done by debug. Trace runs on a different thread thus it does not impact the main code thread.

As per Professional ASP.NET 4 in C# and VB by Bill Evjen, Scott Hanselman, Devin Rader, you can put as many calls to Debug.Write as you want in your application without affecting your performance when you compile in Release mode. This enables you to be as verbose as you want during the debugging phase of development.

Most people keep TRACE defined even for release builds and use the configuration file to turn tracing on and off. More than likely , the benefits you gain from making tracing available to your users far outweigh any performance issues that might arise.

Typically, you want to use tracing and Trace.Write for any formal information that could be useful in debugging your application in the production environment. Trace.Write gives you everything that Debug.Write does, except it uses the TRACE preprocessor directive and is not affected by Debug or Release builds.

For more on difference between Debug & Trace, please see below links:

1. Difference between Debug.Write and Trace.Write. [Link]
2. A Treatise on Using Debug and Trace classes, including Exception Handling. [Link]
3. Difference Between Debug and Trace. [Link]
4. How will you differentiate between trace and debug in ASP.NET? [Link]