Tracing Example

We can configure the "tracing" section at the server level in the ApplicationHost.config file, or at the web application level or directory level in a web.config file and see how to enable tracing in application.

Enable Tracing in application

Tracing in allows you to see diagnostic information about a page request. Tracing enables you to view a page's execution cycle, display diagnostic information at run time, and debug your application.

There are two ways you can enable Tracing in

  • Page Level Tracing
  • Application Level Tracing
Tracing is disabled by default in an ASP.NET application.

If you enable tracing, ASP.NET will append a series of execution details about the page request at the bottom of the page.

Page Level Tracing

To enable tracing in your page simply add Trace="true" TraceMode="SortByCategory" in your page directive

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WTRWebForm._Default" Trace="true" TraceMode="SortByCategory" %>

TraceMode is optional, ="Default | SortByCategory | SortByTime"

After enabling Trace on your page, simply page F5 to refresh the page, you will be able to see the list of tables appearing with following headers.

  • Request Details
  • Trace Information
  • Control Tree
  • Session State
  • Application State
  • Request Cookies Collection
  • Response Cookies Collection
  • Headers Collection
  • Response Headers Collection
  • Form Collection
  • Querystring Collection
  • Server Variables

Application Level Tracing

Instead of enabling tracing for one particular page, you also can enable tracing for entire application. If you do that, every page in your application will display the trace information.

To understand the impact of application level tracing let’s remove the page level tracing first.

Now, open your web.config file and add the following <trace /> tag inside the system.web tag

<trace enabled="true" pageOutput="true" requestLimit="30" localOnly="false"/>

Now if you check all the pages in your application has been trace enabled
Notice, there are few additional parameters in above trace tag.

  • PageOutput
    Default is false. If true then it will display trace both in pages and in the trace viewer (trace.axd)
  • RequestLimit
    Default is 10, Indicate the number of trace requests to store on server
  • LocalOnly
    Default is true, if true then the trace viewer (trace.axd) available only on the host Web server

Learn more about How to deal with tracing in application.

Hire Asp.Net Developer Tracing Example: Enable tracing application Interview Questions Answers MVC interview Core question application development tutorials with real-time examples create web application with SQL database step-by-step.
Asp.Net C# Examples | Join Asp.Net Course | Learn MVC | Core Tutorial