![]() |
Web Development »
Trace and Logs »
Trace / Logs
Intermediate
Tracing web application with ASP.NETBy Chandrashekhar KulkarniThis article explains tracing machanism of .NET. |
Windows, .NET, ASP.NET, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
When 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.
When this method is used, the trace output is displayed on the page that is executed.
In this method, the tracing results are not displayed on the page but these are stored on the web server and in the root folder of the application in a file named as �trace.axd�. After execution of the pages, this file can be viewed on the browser. For example http://yourApplicationroot/trace.axd.
The tracing can be enabled at two scopes:
The page level tracing can be enabled using page directive called �Trace�. If you look at the top of the page, you will find a line something like below:
<%@ Page Language="vb" AutoEventWireup="False" Trace="True"
Codebehind="TraceTest.aspx.vb" Inherits="TracingExample.Test"%>
Also, we have inbuilt Trace object to enable and disable the tracing dynamically. In the page, on Load event if you write the below line, the tracing will be enabled.
Trace.IsEnabled = True
When 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" />
Enabled - Enable or Disable tracing for entire application.
PageOutput � If this attribute value is set to �true� then the trace output will be displayed on the page. If value of this attribute is set to false trace, then the trace output can be retrieved using browser. Typically the URL would be http://<yourAppliccationRoot>/trace.axd.
RequestLimit� This attribute is active only when the PageOutput attribute value is set to false. This attribute defines the number of page requests that are to be traced.
TraceMode � To manage the order of the trace output, this attribute is used. For Example � SortByTime, SortByCategory etc.
localOnly - Set this attribute to "false" if you want access the trace log from any client. Otherwise the log will be displayed on local machine only.When the trace is enabled we get the trace output. This output contains lot of details, some of the sections are as follows:
Trace.Write or Trace.Warn.
There 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 QueryString and enable or disable the trace.
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 Warn method. When Warn method is used the trace output will display the given message in red.
If Trace.IsEnabled Then
Trace.Warn (�Sample trace output / Warning / Custom message�)
End If
Refer Msdn.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 Apr 2005 Editor: Sumalatha K.R. |
Copyright 2005 by Chandrashekhar Kulkarni Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |