Subscribe

RSS Feed (xml)

Enabling Page Level Tracing

In order for page level tracing to be enabled, you need to add the


Trace attribute to the


@ Page directive.


<%@ Page Language="VB" Trace="true"%>



The default value of the Trace attribute is false, which means that it is disabled. In




order to enable it, you simply set its value to true. In <script runat="server" />


block or codebehind:


Private Sub Page_Load(Source As Object, E As EventArgs)


Trace.Write("Page_Load", "Declaring and initializing variables.")


Dim _A As Integer = 10


Dim _B As Integer = 20


Trace.Write("Page_Load", "Applying add operation.")


_A += _B


Trace.Write("Page_Load", "Variable values changed.")


Trace.Write("_A", _A)


Trace.Write("_B", _B)


End Sub


Trace.Write can accept up to three arguments-the first one is the category for the


message, the second is the actual message to display, and the third is the exception


information displayed after the message.The following listing demonstrates all three


arguments:


...


...


Try


'code goes here


Catch _Error As Exception


Trace.Write("Category", "Message", E)


End Try


Comments


In order to display Trace messages from your code, use either the Trace.Write() or the


Trace.Warn() statement.The difference between the two is that Trace.Warn shows the


output text in red, indicating a warning, whereas Trace.Write() shows output in black


text. Both methods accept the same number and type of arguments.


You can also use the Trace.IsEnabled Boolean property to test whether tracing is


enabled prior to performing an expensive operation, such as looping through all values


on the page as part of a Trace output operation.


Note that to access tracing outside of a page, such as in a custom control, you must


refer to the current Web context by using System.Web.HttpContext.Current.Trace()


instead of just Trace() or Page.Trace().




Technorati :

No comments:

Archives

Variety in the Web World