(c) 2002 Visual Studio Magazine 
Fawcette Technical Publications

Issue: February 2002
Section: ASP.NET
Author: Scott Jamison

VB.NET	Use the Trace Object to Add Tracing to Your Code
Listing 1	In this code, you add the Trace.Write statements in places where you want diagnostics. A benefit of using Trace is that you don't have to remove the code at deployment, because a simple directive disables it.

Private Sub Page_Load(ByVal sender As _
	System.Object, ByVal e As System.EventArgs) _
	Handles MyBase.Load
	Trace.Write("CUSTOM", "In page_load")
	If Page.IsPostBack() Then
		' Do not load them again
		Trace.Warn("CUSTOM", "Not loading " & _
			"initial values due to postback")
	Else
		Trace.Write("CUSTOM", "Adding values " & _
			"to drop down list...")
		DropDownList1.Items.Add("Apple")
		DropDownList1.Items.Add("Banana")
		DropDownList1.Items.Add("Cherry")
	End If
End Sub

Private Sub DropDownList1_SelectedIndexChanged( _
	ByVal sender As System.Object, ByVal e As _
	System.EventArgs) Handles _
	DropDownList1.SelectedIndexChanged
		Trace.Write("CUSTOM", "DropDown1 " & _
			"selection changed")
		Trace.Write("CUSTOM", "DropDown1 value =" _
			+ DropDownList1.SelectedItem.ToString _
			())
End Sub

Private Sub Button1_Click(ByVal sender As _
	System.Object, ByVal e As _
	System.EventArgs) Handles Button1.Click
	Trace.Write("CUSTOM", "Button1 clicked")
End Sub
