Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trace vs Debug in .NET BCL

It seems that the

  • System.Diagnostics.Debug, and
  • System.Diagnostics.Trace

are largely the same, with the notable exception that Debug usage is compiled out in a release configuration.

When would you use one and not the other? The only answer to this I've dug up so far is just that you use the Debug class to generate output that you only see in debug configuration, and Trace will remain in a release configuration, but that doesn't really answer the question in my head.

If you're going to instrument your code, why would you ever use Debug, since Trace can be turned off without a recompile?

like image 352
Ben Collins Avatar asked Oct 07 '08 19:10

Ben Collins


People also ask

What is the difference between trace and debug?

Tracing is a process about getting information regarding program's execution. On the other hand debugging is about finding errors in the code.

Is trace higher than debug?

Ans. TRACE designates finer grained informational events than the DEBUG. TRACE is level lower than DEBUG.

What is trace C#?

Tracing helps to see the information of issues at the runtime of the application. By default Tracing is disabled. Tracing has the following important features: We can see the execution path of the page and application using the debug statement. We can access and manipulate trace messages programmatically.

What is trace in Visual Studio?

Tracing is a feature in Visual Studio that allows the programmer to put a log message onto the main output window. The mechanism is fairly simple to use. It is only active with debug builds, in a release build none of the trace messages will be displayed.


2 Answers

The main difference is the one you indicate: Debug is not included in release, while Trace is.

The intended difference, as I understand it, is that development teams might use Debug to emit rich, descriptive messages that might prove too detailed (or revealing) for the consumer(s) of a product, while Trace is intended to emit the kinds of messages that are more specifically geared toward instrumenting an application.

To answer your last question, I can't think of a reason to use Debug to instrument a piece of code I intended to release.

Hope this helps.

like image 137
Jared Avatar answered Oct 01 '22 03:10

Jared


The only difference between trace and debug is that trace statements are included by default in the program when it is compiled into a release build, whereas debug statement are not.

Thus, the debug class is principally used for debugging in the development phase, while trace can be used for testing and optimization after the application is compiled and released.

like image 28
sandy101 Avatar answered Oct 01 '22 01:10

sandy101