Access to trace information in asp.net code

Source: Internet
Author: User
Tags format
asp.net| Access asp.net 2.0 allows you to access the trace information for each request through code in the TraceFinished event. The TraceFinished event is raised by the TraceContext object, which is used to expose trace messages after all request information has been collected. You can use this event to make different output of the trace information. The following code is the output trace information with the program.

C#:

<%@ Page language= "C #"%>
<script runat= "Server" >
protected void Page_Load (object sender, System.EventArgs e)
{
trace.tracefinished + = new Tracecontexteventhandler (ontracefinished);
Trace.Write ("Custom category", "Custom Trace Message");
}
private void Ontracefinished (object sender, Tracecontexteventargs e)
{
foreach (Tracecontextrecord TCR in E.tracerecords)
{
Response.Write (String. Format (<li> trace Category: {0} trace message: {1} ", TCR.) Category, TCR. message));
}
}
</SCRIPT>
VB.net:

<%@ Page language= "VB"%>
<script runat= "Server" >
Protected Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs)
AddHandler trace.tracefinished, AddressOf ontracefinished
Trace.Write ("Custom category", "Custom Trace Message")
End Sub
Private Sub ontracefinished (ByVal sender as Object, ByVal e as Tracecontexteventargs)
Dim TCR as Tracecontextrecord
For each TCR in E.tracerecords
Response.Write (String.Format ("<li> trace Category: {0} trace message: {1}", TCR.) Category, TCR. Message))
Next
End Sub

</SCRIPT>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.