Chapter 8: Debugging and Tracing ASP.NET Applications


Overview

As application developers, we strive to deliver a product that meets requirements and is free from defects. Although we all want to accomplish this goal with one cycle of development, we rarely get this lucky. Application development involves an iterative cycle of creating code and testing it in different environments. The process starts in the development environment, where code is written, compiled, and unit tested . The application then moves into the quality assurance environment for functional and integration testing. Finally, it moves into the production environment where it is deployed in its release version.

The application development cycle is iterative because it takes successive attempts to resolve exceptions in applications. Generally, the exceptions that developers encounter fall into two distinct groups:

  • Syntax/compilation exceptions: These exceptions prevent code from compiling and include type-referencing issues and incomplete function references. The compiler usually intercepts these exceptions, which do not make it into the build. Dynamic type casting can cause unexpected behavior on the test or production servers because it can introduce issues involving missing or unregistered DLLs or COM components with incompatible versions. This may cause exceptions that you would otherwise catch at compile-time.

  • Logical/semantic exceptions: These are exceptions where the code syntax is correct, but the logic execution causes problems. Examples include array-referencing exceptions, where the code references an index that is out of bounds; operator overflow exceptions, such as inadvertently dividing by zero; or exceptions caused by inadvertently passing null references into a function.

You routinely have to debug your code and set traces throughout the application development process to find and fix exceptions. Debugging is the process of diagnosing the precise nature of a known exception and then resolving it. Tracing is the process of tracking and logging the execution of an application at runtime.

You use debugging mostly during the development cycle to identify and correct the logical and semantic errors that prevent your application from running correctly.

You use tracing often during integration testing and in the production environment to gather information on errors that are not easily reproduced in the development and testing environments. A production application essentially runs unattended and may not log enough information about an error for the developer to resolve the issue. Tracing allows you to report information from strategic locations within the application and write it to a log for future reference.

The .NET Framework Software Development Kit (SDK) and Visual Studio .NET (VS .NET) provide an excellent set of tools for diagnosing and resolving application issues. The .NET Framework provides specialized Debug and Trace classes that provide access to a rich amount of information about errors and application state, including detailed call stacks. The Debug and Trace classes help troubleshoot logical and semantic errors not caught by the complier or integrated development environment (IDE). This includes errors due to incorrect logic or unforeseen user input. To find and resolve these types of errors, you must have the ability to monitor specific data and control the application flow during runtime.

ASP.NET has access to the same debugging and tracing functionality that is available to other application types. In addition, ASP.NET supports the TraceContext class, which is a subclass of the Trace class that provides specialized tracing capabilities for ASP.NET Web applications. The capabilities of ASP.NET enable developers to debug and trace applications, as well as to incorporate event logging and performance counters in the application. This ability is commonly referred to as instrumentation .

Instrumentation comprises the following features:

  • Debugging: Diagnosing and resolving programming issues during development

  • Tracing: Monitoring the execution of an application at runtime by logging informative messages

  • Event logging: Components that help to track major events in the execution of the application

  • Performance counters: Components that help track the performance of your application

In this chapter we discuss the tools provided by the .NET Framework SDK and VS .NET that support debugging, tracing, and logging within ASP.NET applications.




Performance Tuning and Optimizing ASP. NET Applications
Performance Tuning and Optimizing ASP.NET Applications
ISBN: 1590590724
EAN: 2147483647
Year: 2005
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net