ASP.NET Tip: Adding Tracing to an Application Wisconsin

Tracing down errors in web applications and services is no easy task. To make it simpler, learn how to add trace statements to your code. They appear only when tracing is enabled on the web page or the web site.

Local Companies

Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
Electroniclaim
262-240-9700
11357 N. Port Washington Rd
Mequon, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
HarrisData
800-225-0585
13555 Bishops Court
Brookfield, WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI

ASP.NET Tip: Adding Tracing to an Application

provided by: 
Originally published at Internet.com


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.

Step 1 is to enable tracing, either at a page or site level. To enable tracing for a single page, add the following to the @Page directive in your ASPX file: Trace="true"

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.

If you add this to a normal web page, you'll get all of this information: * 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

Having all this information can make it much easier to debug issues, even before you add your custom messages.

To add custom messages to the trace output, you can use the Trace object property of the Page class to send messages into the list of events that is dumped to the web page. Here's an example: Trace.Write("Current value of variable: " & variableValue.ToString());

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.

About the Author

Eric Smith is the owner of Northstar Computer Systems, a web-hosting company based in Indianapolis, Indiana. He is also a MCT and MCSD who has been developing with .NET since 2001. In addition, he has written or contributed to 12 books covering .NET, ASP, and Visual Basic. Send him your questions and feedback via e-mail at questions@techniquescentral.com.

Author: Eric Smith

Read article at Internet.com site

Featured Local Company

Wireless Direct

1.866.707.8498
BOX 71101
shorewood, WI
http://www.prepaidwireless.2ya.com

Regional Articles
- ASP.NET Tip: Adding Tracing to an Application Appleton WI
- ASP.NET Tip: Adding Tracing to an Application Baraboo WI
- ASP.NET Tip: Adding Tracing to an Application Beaver Dam WI
- ASP.NET Tip: Adding Tracing to an Application Beloit WI
- ASP.NET Tip: Adding Tracing to an Application Brookfield WI
- ASP.NET Tip: Adding Tracing to an Application Burlington WI
- ASP.NET Tip: Adding Tracing to an Application Cedarburg WI
- ASP.NET Tip: Adding Tracing to an Application Chippewa Falls WI
- ASP.NET Tip: Adding Tracing to an Application Cudahy WI
- ASP.NET Tip: Adding Tracing to an Application De Pere WI
- ASP.NET Tip: Adding Tracing to an Application Delavan WI
- ASP.NET Tip: Adding Tracing to an Application Eau Claire WI
- ASP.NET Tip: Adding Tracing to an Application Elkhorn WI
- ASP.NET Tip: Adding Tracing to an Application Fond Du Lac WI
- ASP.NET Tip: Adding Tracing to an Application Fort Atkinson WI
- ASP.NET Tip: Adding Tracing to an Application Franklin WI
- ASP.NET Tip: Adding Tracing to an Application Green Bay WI
- ASP.NET Tip: Adding Tracing to an Application Hartland WI
- ASP.NET Tip: Adding Tracing to an Application Janesville WI
- ASP.NET Tip: Adding Tracing to an Application Kaukauna WI
- ASP.NET Tip: Adding Tracing to an Application Kenosha WI
- ASP.NET Tip: Adding Tracing to an Application La Crosse WI
- ASP.NET Tip: Adding Tracing to an Application Lake Geneva WI
- ASP.NET Tip: Adding Tracing to an Application Manitowoc WI
- ASP.NET Tip: Adding Tracing to an Application Marinette WI
- ASP.NET Tip: Adding Tracing to an Application Marshfield WI
- ASP.NET Tip: Adding Tracing to an Application Menasha WI
- ASP.NET Tip: Adding Tracing to an Application Menomonee Falls WI
- ASP.NET Tip: Adding Tracing to an Application Menomonie WI
- ASP.NET Tip: Adding Tracing to an Application Merrill WI
- ASP.NET Tip: Adding Tracing to an Application Middleton WI
- ASP.NET Tip: Adding Tracing to an Application Milwaukee WI
- ASP.NET Tip: Adding Tracing to an Application Mosinee WI
- ASP.NET Tip: Adding Tracing to an Application Mukwonago WI
- ASP.NET Tip: Adding Tracing to an Application Muskego WI
- ASP.NET Tip: Adding Tracing to an Application Neenah WI
- ASP.NET Tip: Adding Tracing to an Application New Berlin WI
- ASP.NET Tip: Adding Tracing to an Application Oak Creek WI
- ASP.NET Tip: Adding Tracing to an Application Oconomowoc WI
- ASP.NET Tip: Adding Tracing to an Application Onalaska WI
- ASP.NET Tip: Adding Tracing to an Application Oshkosh WI
- ASP.NET Tip: Adding Tracing to an Application Pewaukee WI
- ASP.NET Tip: Adding Tracing to an Application Racine WI
- ASP.NET Tip: Adding Tracing to an Application Rhinelander WI
- ASP.NET Tip: Adding Tracing to an Application Rice Lake WI
- ASP.NET Tip: Adding Tracing to an Application River Falls WI
- ASP.NET Tip: Adding Tracing to an Application Schofield WI
- ASP.NET Tip: Adding Tracing to an Application Shawano WI
- ASP.NET Tip: Adding Tracing to an Application Sheboygan WI
- ASP.NET Tip: Adding Tracing to an Application South Milwaukee WI
- ASP.NET Tip: Adding Tracing to an Application Stevens Point WI
- ASP.NET Tip: Adding Tracing to an Application Sturgeon Bay WI
- ASP.NET Tip: Adding Tracing to an Application Sun Prairie WI
- ASP.NET Tip: Adding Tracing to an Application Superior WI
- ASP.NET Tip: Adding Tracing to an Application Thiensville WI
- ASP.NET Tip: Adding Tracing to an Application Two Rivers WI
- ASP.NET Tip: Adding Tracing to an Application Watertown WI
- ASP.NET Tip: Adding Tracing to an Application Waukesha WI
- ASP.NET Tip: Adding Tracing to an Application Waupaca WI
- ASP.NET Tip: Adding Tracing to an Application Wausau WI
- ASP.NET Tip: Adding Tracing to an Application West Bend WI
- ASP.NET Tip: Adding Tracing to an Application Whitewater WI
- ASP.NET Tip: Adding Tracing to an Application Wisconsin Rapids WI
Related Local Event
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Retail & Consumer Services
Business Services Entertainment Industrial Goods & Services Software
Career Family Insurance Technology
Cars Financial Services Internet Telecommunications
Computer Hardware Food & Beverage Legal Transportation & Logistics
Construction Health Pets Travel
Education Home Electronics Real Estate Wedding