Newbie Q - debug or trace?

G

Guest

Hi,
as a newbie to C# I was not clear on the difference and usage of
the trace and debug classes.

I know how to use them and the debug.assert method seems
very akin to unit testing practices.

They seem very similar to me - are they? is it something to
do with implementation on the CLR level or do they indeeed
have different 'logical' uses?

Thanks
Charlie
 
D

David Hogue

CharlieOz1 said:
Hi,
as a newbie to C# I was not clear on the difference and usage of
the trace and debug classes.

I know how to use them and the debug.assert method seems
very akin to unit testing practices.

They seem very similar to me - are they? is it something to
do with implementation on the CLR level or do they indeeed
have different 'logical' uses?

Thanks
Charlie
The only real difference between the debug and trace classes is that the
debug class only works if you compile in debug mode. If you compile in
release mode Debug.WriteLine() won't do anything.

I haven't used Debug.Assert in .net, but I have seen asserts commonly
used in C/C++ programs. It's purpose was to check that a condition was
valid at runtime and if not exit the program printing a file name, line
number, and some other information.

-David
 
C

Cerebrus

Hi,

David has already cited the main difference between Debug and Trace.

Applying a broader perspective, I would say that Debug is more useful
during the development phase (when you're working in the Debug
compilation mode) of a project, while Trace is more useful during the
Maintenance phase (when your project has been released and deployed at
the client). Using Trace in this condition allows you to keep getting
and storing diagnostic information about program crashes, or exceptions
generated.

Also note that Debug.Asserts checks for a condition to be *false*. Only
then it outputs to the call stack.

Regards,

Cerebrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top