difference between the Debug class and Trace class

Posted by Saranya Boopathi under C# on 6/26/2013 | Points: 10 | Views : 1131 | Status : [Member] | Replies : 2
What's the difference between the Debug class and Trace class?

Saranya Boopathi


Posted by: aswinialuri-19361 on: 6/26/2013 [Member] Starter | Points: 25

hi Saranya,
Main difference is debug works for debugging a code
Trace works for debug and release a code
the main advantage of using trace over debug is to do performance analysis which cannot be done by debug.
Trace runs on a different thread thus it does not impact the main code thread.
if you need to enable a trace in a particular code
you must mention trace="true" in the page directives then it is enabled.

Mark as Answer if it helps you
Aswini Aluri

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/27/2013 [Member] [MVP] Silver | Points: 25

Trace and Debug - There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.

Tracing is actually the process of collecting information about the program's execution. Debugging is the process of finding & fixing errors in our program. Tracing is the ability of an application to generate information about its own execution. The idea is that subsequent analysis of this information may help us understand why a part of the application is not behaving as it should and allow identification of the source of the error.

We shall look at two different ways of implementing tracing in .NET via the System.Web.TraceContext class via the System.Diagnostics.Trace and System.Diagnostics.Debug classes. Tracing can be thought of as a better alternative to the response.writes we used to put in our classic ASP3.0 code to help debug pages.

If we set the Tracing attribute of the Page Directive to True, then Tracing is enabled. The output is appended in the web form output. Messeges can be displayed in the Trace output using Trace.Warn & Trace.Write.

NOTE The only difference between Trace.Warn & Trace.Write is that the former has output in red color. If the trace is false, there is another way to enable tracing. This is done through the application level. We can use the web.config file and set the trace attribute to true. Here we can set <trace enabled=false .../>

Note that the Page Directive Trace attribute has precedence over th application level trace attribute of web.config. While using application level tracing, we can view the trace output in the trace.axd file of the project.


If this post helps you mark it as answer

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response