Trace vs Debug in .NET BCL

It seems that

basically match, with the notable exception that Debug is used in the release configuration.

When will you use one and not the other? The only answer to this question that I dug up so far is that you use the Debug class to generate the output, which you see only in the debug configuration, and Trace will remain in the release configuration, but in fact it does not answer mine question.

If you intend to use your code, why use Debug , since Trace can be disabled without recompiling?

+48
debugging c # instrumentation
Oct 07 '08 at 19:00
source share
6 answers

The main difference is that you specify: Debug is not included in release, but Trace is.

The supposed difference, as I understand it, is that development teams can use Debug to distribute rich descriptive messages that may be too detailed (or revealing) for the consumer (s) of the product, while Trace is designed to emit message types, which are more specifically application-oriented applications.

To answer your last question, I cannot think of a reason to use Debug to process the piece of code I was planning to release.

Hope this helps.

+47
07 Oct '08 at 19:07
source share

Debugging is used for clean debugging purposes. It emits rich messages in debug mode (debug mode).

Tracing helps with application debugging, bug fixing, and profiling (after release).

The debug class is useless in release mode.

+5
Dec 26 '11 at 6:14
source share

I would look at using log4net for tracking, as its capabilities are much more flexible and reliable.

But for true debugging messages, which I never intend to see, except me or the internal tester, I would probably stick with Debug.

+3
Oct 07 '08 at 19:04
source share

The only difference between tracing and debugging is that trace instructions are included by default in the program when they are compiled into the release build, while the debug command is not.

Thus, the debugging class is mainly used for debugging at the development stage, and tracing can be used for testing and optimization after compiling and publishing the application.

+3
May 30, '09 at 13:50
source share

For highly sensitive blocks of code left compiled but disabled, there may be a difference in performance.

+2
Oct 07 '08 at 19:08
source share

You answered your question. If Debug messages remained, people could see them. For example, let's say you:

 Debug.WriteLine ("Connecting to DB with username: blah and PW: pass");

Anyone who decompiles your code can see this. But this can be something vital for you during testing.

The trace is different. If you are going to do Trace, I would just use log4net.

+1
Oct 07 '08 at 19:07
source share



All Articles