For some applications, such as console or Windows Forms applications, it's fairly easy to step through them to debug an issue. However, tracing down errors in web applications and services can be difficult, especially if they happen only in production environments where debugging isn't possible. In these cases, it's helpful to be able to add trace statements to your code that appear only when tracing is enabled on the web page or the web site
By default, this will dump the tracing information at the bottom of the web page. In most debugging/tracing situations, this is sufficient. However, if you're working on tracing in an entire site, you can make the change in the Web.config file instead of in each web page. To do this, open up the Web.config and add the following line:
The enabled attribute turns tracing on and off. The localOnly attribute controls whether the trace output shows up on machines other than the web server. In my own development environment, I use VMWare Workstation to host a Windows 2003 Server instance. So, I have to turn this attribute to false to see the output when I bring up a browser outside the virtual machine. If you are running IIS locally on your development machine, you won't need to set this attribute. The final attribute indicates that the output should be dumped at the bottom of the page. You also can opt to put the tracing in a separate file, but I've found that having the information right on the page is far easier to work with.
- Overall information about the request
- A list of events and the time each event took to complete
- A tree of all the controls on the page, showing each control's name and the amount of memory each one took in the ViewState, rendering, and control state
- A list of session variables and their current values
- A list of application variables and their current values
- The cookies from the request and the response
- Request and response headers
- Contents of the Form, QueryString, and ServerVariables collections
This will print the line of text at the appropriate time during all the other events that are documented in the trace output. Because tracing can be turned on and off through a configuration file, this is an easy way to leave in debugging commands that you may need in the future. However, because it can be easily enabled and disabled, be careful about how much personal information, such as identification numbers and passwords, you dump into the trace output.