Recent Articles

How To Use Breakpoints
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005.

How To Use The Exception Assistant
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005.

ASP.NET: Testing a file-system web site with IIS
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005.

ASP.NET School For The Online Mind
A New Jersey firm now offers three online courses in ASP.NET programming, delivered through a browser.

Blinq Instantly Builds ASP.NET Sites
Microsoft's Web Language Integrated Query tool called Blinq can generate ASP.NET websites based on on database schema.



Recent WebProNews Articles

Universal Angry At MySpace, YouTube
Universal Music Group CEO Doug Morris called the two media sharing websites "copyright infringers" and hinted at legal action against them. YouTube has until the end of September to appease Morris and company...

Google.org Aspires To Charity, Profits
Google.org has been getting a fair amount of attention lately. "The philanthropic arm of Google" was formed in late 2004, and, unlike most charitable ventures, is a for-profit entity. Although that sounds somewhat troubling...

VON: Andrew Baron Rockets In
Rocketboom's stormy breakup with host Amanda Congdon captivated the blogosphere. Baron started over with a new host, Joanne Colan, and arrived at Fall 2006 VON to talk about his view of the nascent online video industry.

VON: Viewing TV From Afar
Time and place shifting have become more important to people when it comes to viewing television. Tivo and other technologies indicate how this demand has shifted power slightly from the broadcaster to the consumer.


09.15.06


ASP.NET: How To Create Custom Trace Messages

By Joel Murach

This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005.

The Trace feature is an ASP.NET feature that displays some useful information that you can't get by using the debugger. Because the debugger works so well, you probably won't need to use the Trace feature very much, but you should at least be aware of the information that it can provide...

How to Create Custom Trace Messages

In some cases, you may want to add your own messages to the trace information that's generated by the Trace feature. This can help you track the sequence in which the methods of a form are executed or the changes in the data as the methods are executed. Although you can also do this type of tracking by stepping through the methods of a form with the debugger, the trace information gives you a static listing of your messages.


Note, however, that you can also create this type of listing using tracepoints as described earlier in this chapter. The advantage to using tracepoints is that you can generate trace information without adding code to your application. In addition, this output is generated only when you run an application with debugging. In contrast, you have to add program code to add custom trace messages, and the trace output is generated whenever the Trace feature is enabled. Because of that, you may not want to create custom trace messages. But I've included it here in case you do.

To add messages to the trace information, you use the Write or Warn method of the TraceContext object. This is summarized in figure 4-16. The only difference between these two methods is that messages created with the Warn method appear in red. Notice that to refer to the TraceContext object, you use the Trace property of the page.

When you code a Write or Warn method, you can include both a category and a message or just a message. If you include just a message, the category column in the trace output is left blank. If you include a category, however, it appears as shown in this figure. In most cases, you'll include a category because it makes it easy to see the sequence in which the methods were executed.

If you want to determine whether tracing is enabled before executing a Write or Warn method, you can use the IsEnabled property of the TraceContext object as shown in the example in this figure. Normally, though, you won't check the IsEnabled property because trace statements are executed only if tracing is enabled.

Common members of the TraceContext class

Property

IsEnabled - True if tracing is enabled for the page.

Method

Write(message) - Writes a message to the trace output.

Write(category, message) - Writes a message to the trace output with the specified category.

Warn(message) - Writes a message in red type to the trace output.

Warn(category, message) - Writes a message in red type to the trace output with the specified category.

Code that writes a custom trace message



A portion of a trace that includes a custom message



Description

• You can use the TraceContext object to write your own messages to the trace output. The TraceContext object is available through the Trace property of a page.

• Use the Write method to write a basic text message. Use the Warn method to write a message in red type.

• Trace messages are written only if tracing is enabled for the page. To determine whether tracing is enabled, you use the IsEnabled property of the TraceContext object.


About the Author:
Joel Murach has been writing and editing for more than 10 years. During that time, he sharpened his programming skills as a contract programmer in San Francisco and his instructional skills as a trainer for HarperCollins Publishing. He always brings a vision to his projects that leads to improved effectiveness for his readers.

About WebProASP
WebProASP is a collection of up to date tutorials and insightful articles designed to help ASP users of any skill level implement successful ASP systems and practices. ASP Strategies and Tactics for Business

WebProASP is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQlProNews.com
ITcertificationNews.com SysAdminNews.com
WebProASP.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com




-- WebProAsp is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



ASP Strategies and Tactics for Business WebProASP News Archives About Us Feedback WebProASP Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact