What is ASP.Net tracing

ASP.Net tracing

Tracing is an activity to follow execution path and display the diagnostic information related to a specific Asp.Net web page or application that is being executed on the web server. Tracing can be enabled at development environment as well as in the production environment. These information can help you to investigate errors or unwanted results while ASP.NET processes a page request. You can view trace information at the bottom of individual pages and also you can use the trace viewer to view these trace information that is collected and cached by ASP.NET when tracing is enabled.

In Asp.Net Tracing is disabled by default. Trace statements are executed and shown only when tracing is enabled. You can enabled tracing in two levels.

  1. Page Leve Tracing
  2. Application Level Tracing

You can enabled individual pages as well as you can enabled your application's Web.config file to display trace information. When you enabled it application level, it display all pages trace information unless the page explicitly disables tracing.

Page Leve Tracing

We can control whether tracing is enabled or disabled for an Asp.Net page with the Trace attribute of the @ Page directive.

<%@ Page Trace="true" %> <%@ Page Language="VB" Trace="true" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Application Level Tracing

When we enable application level tracing, trace information is gathered and processed for each page in that application. We can enable application level tracing by using the trace element in the Web.config file.

<configuration> <system.web> <trace enabled="true" pageOutput="true" requestLimit="50" localOnly="false" mostRecent="true"traceMode="SortByTime" /> </system.web> </configuration>

By default, application level tracing can be viewed only on the local Web server computer. The above configuration enables an application trace configuration that collects trace information for up to 50 requests.