|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
What is Tracing?Tracing is an activity of recording the diagnostic information related to a specific web page that is being executed on the web server. In this discussion we will consider ASP.NET related tracing technique. Need of TracingWhen the application are in development stage, developers can use in-built debuggers for troubleshooting, but in the production environment, using debuggers becomes a huge task for administrators considering the security and related issues. To debug Classic ASP applications, we were having no mechanism to track the execution flow of ASP pages. Thanks to .NET !!. Using .NET technology we can trace the flow with really less efforts. To collect the statistics like execution time, contents of certain object, “response.write” was the only way in classic ASP. Using trace we are now able to view the HTTP headers, session state and likewise information on the trace output. Also, we have flexibility to add our own contents in the trace output. Tracing Methods
How Do I trace?The tracing can be enabled at two scopes:
Working with Page Level TracingThe page level tracing can be enabled using page directive called “ <%@ Page Language="vb" AutoEventWireup="False" Trace="True"
Codebehind="TraceTest.aspx.vb" Inherits="TracingExample.Test"%>
Also, we have inbuilt Trace.IsEnabled = True
Working with Application Level TracingWhen you are working with page level Tracing, you need to know probable page that is to be traced. If your application is complex and if you want to trace you might not be aware exact page that is to be traced. To avoid this problem we, .NET platform, provides a facility to enable the tracing at application level. As we know that web.config is a file that manages the application level settings. In the same file we can mention setting of the Trace. <trace enabled="true" pageOutput="true" requestLimit="10"
traceMode="SortByTime" localOnly="true" />
Attributes of Trace Tag
Trace OutputWhen the trace is enabled we get the trace output. This output contains lot of details, some of the sections are as follows:
Using Trace ObjectThere are lot of tricks that we can use to enable / disable and write trace. A common and widely used technique is to pass a parameter using For example, you write the below given code in the page load event: If (Context.Request.QueryString("EnableTrace") = "true") Then
Context.Trace.IsEnabled = True
End If
And you give the URL to enable the trace: http://MyAppRoot/mypage.aspx?EnableTrace=true For writing the trace, we use the same object. Anywhere in the page, if the below line is written, then the trace output will display the same. If Trace.IsEnabled Then
Trace.Write (“Sample trace output / Custom message”)
End if
Also, we can use the If Trace.IsEnabled Then
Trace.Warn (“Sample trace output / Warning / Custom message”)
End If
Further ReadingRefer Msdn.
|
|||||||||||||||||||||||||||||||||||||||||||||||