Thursday, January 8, 2009

Tracing in WebComponents Of Application

Tracing with in Web Application components

To identify the problems within the components of the application we need to refer to the current context of the Http request. This can be accomplished by the System. Web Name space.

Import System.Web Namespace in the component
Refer to the current context of the http request while using trace.write to output the trace information to the page or to the log file.


Trace.Write, as in

HTTPContext.Current.Trace.Write.



HTTPContext provides access to the trace object to write the output information.

Disadvantege of using the HTTPContext is it doenot allow not web applications to use the companent it is referring to.
It is impossible to share the component between Web and Non Web Applications.

To share the Component we need to implement Listener class instead of HTTP context.


Suppose we are using add method in the component.

Imports System.Web
----
----
----
public sub addnumbers(Byval a as integer, Byval b as integer)
int total;
// output trace message indicating the start of the Method execution

HttpContext.Current.Trace.Write("In Component", "Before performing addition");
Total=a+b
// output trace message indicating the end of the concatenations
HttpContext.Current.Trace.Write("In Component", "After performing Addition");
End Sub


In the aspx page in which we are using the component,just create instance and use it


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim webComponent As Testcomponet
webComponent = New Testcomponet
'add a string to the string in the component 1000 times
webComponent.addToString(2000, 1000)
End Sub 'Page_Load

No comments:

Post a Comment