Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trace and Debug statements

Im a little confused over how to use the .NET Trace and Debug classes.

Why would you bother using Trace instead of Debug?

Trace.TraceError()
Trace.TraceInformation()
Trace.Assert()

Debug.WriteLine()
Debug.Assert()

Also, I understand that Debug statements are ignored when your in Release config mode, but If trace statements apply all the time, how does this affect performance?

like image 720
Razor Avatar asked Dec 31 '08 00:12

Razor


People also ask

What is a trace in debugging?

One technique that monitors software in real-time debugging is known as "tracing," which involves a specialized use of logging to record information about a program's execution. Programmers typically use this information to diagnose common problems with software and applications.

What is a trace statement?

Trace statements are present in both Debug and Release builds. You place both Debug and Trace statements where you want to output the value of something for the purpose of debugging or checking. This MS support article might be of interest: How to trace and debug in Visual C#

What is the difference between debug write and trace write?

Debug. Write is only effective on builds where the DEBUG flag is defined, while Trace. Write is only effective when the TRACE flag is defined.

What is the difference between trace and debug in C#?

What is difference between Debug and Tracing? Debug is going through the code flow during run time where as tracing is giving details of execution plan, process timing details. Debug and trace enables you to monitor the application for errors and exception with out VS.NET IDE.


1 Answers

At the simplest level, they have different compilation switches - i.e. Debug.WriteLine etc is only toggled if you have the DEBUG compilation symbol (not common for release builds), where-as Trace.WriteLine will usually be included even in release builds.

The Trace route has customizable trace-listeners, that can be plumbed in via configuration; Debug generally goes to a debugger as the listener. Of course, there are 3rd-party trace systems that offer much more flexibility.

like image 50
Marc Gravell Avatar answered Sep 20 '22 14:09

Marc Gravell