With tracing, you can access data from a running application, with the help of a browser. In ASP.NET, you can access to the following information:
- The details of the request
- Trace information: performance information of the Web page’s life cycle events
- Control tree: size information about controls.
- Session state: displays session variables and values
- Application state: displays application variables and their values
- Request cookie collection: list of cookies passed to the server as part of the request
- Response cookie collections: list of cookies passed to the browser as part of the response
- Headers collection: the list of HTTP headers sent with the request
- Form collection: postback values.
- QueryString collection: the variables of the query string.
- Server variables: all server variables.
To enable tracing, you have two options: enable tracing for single pages, or for the whole application. To enable page tracing, you should set the Trace property to true in the @Page directive. Also, you can set it in code-behind, with the Page.Trace.IsEnabled = true; syntax. At page level, you can also include a TraceMode property, which sets the sort order of trace information, by time, or by category. When you set tracing at the page level, the trace output will be added to your page, so never implement this behavior in production applications.
To enable tracing for the whole application, you should modify the web.config as follows:
<trace ebabled=”true” requestLimit=”100” pageOutput=”false” ceMode=”sortByCategory” localOnly=”true” mostRecent=”false” />
|Attributes of Trace|
|Enabled||Enable or disable tracing on the application level. This behavior can be overridden by independent pages, using the @Page directive. To enable tracing on specific pages, when application-level tracing is disabled, set the pageOutput attribute accordingly.|
|traceMode||The possible values are SortByTime, which sorts the tracing information by time, or SortByCategory.|
|localOnly||Decides whether tracing information should be provided just for local clients, or everyone else. Always set to true when publishing your application.|
|pageOutput||Determines whether the tracing information should be included for pages or not. When set to false, you can view trace data in the Trace.axd site on the root level.|
|requestLimit||Specifies the number of HTTP requests to be traced. Maximum us 10.000. Works only when application level tracing is enabled.|
|mostRecent||Determines whether the most recent number of HTTP request should be stored in the trace information, or only the first requsetLimit number of requests.|
|writeToDiagnosticsTrace||If set to true, tracing information will be forwarded to any trace listeners signed up to your application.|
When enabled, application-level trace information can be viewed by requesting Trace.axd in the root of the application.
You can add your own tracing messages to the output, simply calling Trace.Write(string Category, string Message) or Trace.Warn(string Category, string Message). The only difference between the two is that Trace.Warn shows your message written with red letters.