What are the Differences between the Debug class and Trace class? - Coding Sharp

What are the Differences between the Debug class and Trace class?

Debug and Trace both classes are included in Systems.Diagnostics namespace and have very similar methods. The main difference is that call to Debug class is included in Debug mode only while call to Trace class will be included in Debug as well as Release mode also.

So in short we can say it is advisable to use Debug at the time of application development, while Trace option is used at the time of application deployment, like we can trace any error and write it into log files etc.

What is the differences between a Debug and Release build?

When we are building any .Net project there are two configuration we can select 1 is Debug and another is for Release, While we are developing an application default mode is Debug and programmers keeps is Debug mode for debugging code step by step or line by line. Once project is completed we need to change it to Release mode before generating final build like DLL, EXE or published code.

The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code.

Normally Debug builds are not optimized and it has debugging symbols, while the code build in the Release mode is more optimized, It is very less in size and more faster then Debug mode.

What is the role of .pdb files ?
PDB is stands for Program Database File, it contains the debug information about the application depending on the compiler option that we have used. It holds application state information and debugging information that allows incremental linking of a Debug configuration of out application. PDB file is created when we are running a C# application in Debug mode.

We can set the debug mode in web.config file as shown below

// For Debug mode

<system.web>
<compilation debug="true">

or

// For Release mode

<system.web>
<compilation debug="false">

Happy Debugging