Hi
What is the difference between Debug.Write and Trace.Write ? When should each be used ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Apr 17, 2012, 11:45 PM
The Debug.Write will work while the application is in both Debug Mode and Release Mode. This is normally used while you are going to debug a project. This will not be work when you will define some debug points to your project.
But the Trace.write will work while the application is only in Release Mode. This is used in released version of an application. This will compiled when you will define debug points in your project.
Answer of the second question is in above two line.
hope this help.
SenthilkumarPosted Apr 17, 2012, 11:39 PM
See the official web site of microsoft for debug and trace.
http://support.microsoft.com/kb/815788
Satyapriya NayakPosted Apr 17, 2012, 12:49 PM
Debug.Write: Debug Mode, Release Mode (used while debuging a project)
Trace.write: Release Mode (used in Released verion of Applications)
The Debug.Write call won't be compiled when the DEBUG symbol is not defined (when doing a release build). Trace.Write calls will be compiled. Debug.Write is for information you want only in debug builds, Trace.Write is for when you want it in release build as well.
Trace and Debug - There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.
Tracing is actually the process of collecting information about the program's execution. Debugging is the process of finding & fixing errors in our program. Tracing is the ability of an application to generate information about its own execution. The idea is that subsequent analysis of this information may help us understand why a part of the application is not behaving as it should and allow identification of the source of the error.
We shall look at two different ways of implementing tracing in .NET via the System.Web.TraceContext class via the System.Diagnostics.Trace and System.Diagnostics.Debug classes. Tracing can be thought of as a better alternative to the response.writes we used to put in our classic ASP3.0 code to help debug pages.
If we set the Tracing attribute of the Page Directive to True, then Tracing is enabled. The output is appended in the web form output. Messeges can be displayed in the Trace output using Trace.Warn & Trace.Write.
NOTE The only difference between Trace.Warn & Trace.Write is that the former has output in red color. If the trace is false, there is another way to enable tracing. This is done through the application level. We can use the web.config file and set the trace attribute to true. Here we can set
Note that the Page Directive Trace attribute has precedence over th application level trace attribute of web.config. While using application level tracing, we can view the trace output in the trace.axd file of the project.
Also Please refer Our recommended articles
http://www.c-sharpcorner.com/uploadfile/puranindia/debugging-and-tracing-in-C-Sharp/default.aspx
Thanks
Thanks