Debug and Trace

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

Hi All,

Can someone please tell me what the difference is between
DEBUG and TRACE. From what I can see, they are two
different classes, but with the same members? Whats the
purpose of have two different classes that seem to do the
same thing?

Thanks alot for any help, much appreciated
Kevin
 
Hi Kevin,

Debug is used to debug applications in development, while Trace can used to
log actions in production code.

HTH,

Andrés Taylor
 
Kevin said:
Hi All,

Can someone please tell me what the difference is between
DEBUG and TRACE. From what I can see, they are two
different classes, but with the same members? Whats the
purpose of have two different classes that seem to do the
same thing?

The only difference is that the C# compiler will include calls to the
methods of the Trace class only if TRACE is defined, and to methods of Debug
if DEBUG is defined. The idea is that the latter (Debug) should have rich
descriptive debug messages for use only for debug builds whereas the former
(Trace) should have fewer more succinct messages for release builds.

Personally, I don't subscribe to the idea of leaving trace messages in
release builds. There are several reasons for this:

- if the trace information is important to the user, then the user should
see it in the application UI, if it is used for debugging then it should be
in the debug build only
- if you want to trace information to the event log, then call the event log
directly - even better, use some unmanaged C++ to write messages to the
event log because the EventLog class really sucks in this respect
- if Trace is meant for release builds then why isn't it allowed by default
without having to define TRACE?

Also, if you use DefaultTraceListener the messages will be reported through
the Win32 OutputDebugString and this essentially couples the trace listener
(and the .NET process) to the viewer used to read the debug strings. If the
reader is written badly and takes a long time reading each string then your
..NET application will also have this delay :-(

Richard
 
Back
Top