Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Tracing in asp.net - Part 79

Suggested Videos
Part 76 - Customizing asp.net exception Logging
Part 77 - Sending emails using asp.net
Part 78 - Sending emails in asp.net using SMTP server settings from web.config

Tracing enables us to view diagnostic information about a request and is very useful when debugging application problems. 

In a later video session, we will discuss about, how tracing can be used to solve a performance related problem.



Tracing can be turned on or off 
1. At the application level or
2. At the page level

To enable tracing at the application level set "trace" element's "enabled" attribute to "true" in web.config. This enables tracing for all pages in the application. 
<trace enabled="true"/>

To disable tracing for specific pages, set Trace="false" in the webform's "Page" directive
<%@ Page Language="C#" Trace="false" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>



If tracing is enabled at the application level, the trace messages are written to a file called trace.axd. Trace.xd file can only be accessed locally. To make the trace file available to remote users set localOnly="false". Tracing displays sensitive information, that could be useful to a hacker to hack into the server. So set this attribute to "false" only when it is required.
<trace enabled="true" localOnly="false"/>

To append trace messages at the end of the page set pageOutput="true".
<trace enabled="true" pageOutput="true" localOnly="false"/>

Use RequestLimit attribute to control the number of trace requests that are stored on the server. The default is 10. After this limit is reached, the sever will stop writing to the trace file.
<trace enabled="true" pageOutput="true" requestLimit="5" localOnly="false"/>

If you want to log trace messages, even after the requestLimit has reached set mostRecent attribute to true. When this attribute is set to true, the old entries in the trace log are discarded and the new entries get added.
<trace enabled="true" mostRecent="true" requestLimit="3"/>

No comments:

Post a Comment

It would be great if you can help share these free resources