Debug and Trace discussion

Debug is used during debugging. Trace is writing to the log file. It is kind of like logging. Both are very similar, but do tracing for long term retention, debugging for real time debugging.

When we monitor application execution and performance in development stage is termed as “Debugging” and when you do in deployed environment it’s termed as ‘Tracing’.

Debug provides a set of methods and properties that help debug your code. This class cannot be inherited (i.e. sealed class). Namespace of Debug is system. Diagnostic. Trace is read-only properties which Data from the System.Web.TraceContext object for the current Web request.

Debug Class provides a set of methods and properties that help debug the code. If we use methods in the Debug class to print debugging information and check the logic with assertions, we can make the code more robust without impacting the performance and code size of the shipping product.

We can use the properties and methods in the Trace class to instrument release builds. Instrumentation allows monitoring the health of application running in real-life settings. Tracing helps us the isolate problems and fix them without disturbing a running system.

How can we implement debugging and tracing in ASP.NET?

Debug’ and ‘Trace’ methods as shown in the below code. In the below code we are tracking critical execution points like page load and button click.

protected void Page_Load(object sender, EventArgs e)

{

Debug.Write(“Debug :- The page is loadedn”);

Trace.Write(“Trace :- The page is loadedn”);

}

protected void Button1_Click(object sender, EventArgs e)

{

Debug.Write(“Debug :- Button is clickedn”);

Trace.Write(“Trace :- Button is clickedn”);

}

 

So can we see a quick sample of how tracing information can be viewed?

A quick and dirty way of seeing tracing information is by going to the ASPX front code and put trace=true in the ‘Page’ attribute.

<%@ Page Language=”C#” AutoEventWireup=”true” trace=”true”

CodeBehind=”Default.aspx.cs” Inherits=”WebTracing._Default” %>
Once you have done the same you should be able to see tracing information as shown in the below figure. With trace enabled as true it also displays lot of other things like different page events , session data , hidden field data , http headers etc. I have circled the custom information which we have written using the ‘Trace’ object.

Difference Between Constant and ReadOnly and Static

Understanding Delegates in C#

http://msdn.microsoft.com/en-IN/library/ms186918.aspx

http://stackoverflow.com/questions/21080346/difference-between-object-dynamic-and-var

Untitled

Leave a Reply