Lesson 3: Logging Exceptions
The purpose of this lesson is to introduce ASP.NET Trace functionality to record Web application exceptions.
It appears that ASP.NET tracing is an excellent alternative to a formal, generic .NET exception-handling "code block" when you need to run the ASP.NET application with reduced security privileges since writing to the Application Event Log or writing to the file system could introduce unwanted security risks.
- "Tracing is a technique for recording events, such as exceptions, in an application."
This underscores the idea that tracing is not solely used for exception handling.
- "Building tracing into the .NET Framework ensures that programming techniques are the same across all the applications you develop with .NET Framework."
The lesson suggests that this functionality provides "standardization" for all solutions based on the .NET Framework. Since tracing features are defined in the System.Web.TraceContext class we are free to assume that this 'standard' is confined to ASP.NET applications (HTTP-dependent applications including Web services).
- "Tracing can be turned on or off for an entire Web application or for an individual page in the application..."
Application-level tracing is controlled by declaring the trace element in the Web.config file. Page-level tracing is controlled by declaring the Trace attribute in the @ Page directive.
- "When you have set the @ Page directive's Trace attribute to True or False, you can't restore the default setting from the Properties window in Visual Studio .NET."
In effect, all tracing functionality is controlled through declarative programming. In procedural code, tracing status is read-only through the Trace.IsEnabled property.
-
"The Trace object provides the Write and Warn methods to allow you to write messages to a request's trace information. The two methods are identical with one exception: messages written with Write are displayed in black, whereas messages written with Warn are displayed in red."
-
"...if the <trace> element's PageOutput attribute is set to False in the Web.config file, trace output is written instead to the Trace.axd file in your application's root directory."
The speculation here is that Trace.axd is not a "file" but a dynamically generated resource called from a ASP.NET library.
- "By default, you can view Trace.axd only from the local server running the application."
You can allow remote viewing of Trace.axd by declaring the localOnly attribute of Trace.axd and setting it to false.
- "ASP.NET tracing stops after the server receives the number of HTTP requests entered in the <trace> element's RequestLimit attribute."
When this attribute is not declared, note that the default request limit is 10. To reset the count against the limit send this URI: "Trace.axd?clear=1".