ASP.NET 2.0允许通过代码在TraceFinished事件里来访问每个请求的跟踪信息。TraceFinished事件是由TraceContext对象引发,用于在收集完所有请求信息后公开跟踪消息。可以利用此事件对跟踪信息进行不同的输出。以下代码就是用程序输出跟踪信息。
C#:
<%@ Page Language="C#" %>
<SCRIPT runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
Trace.TraceFinished += new TraceContextEventHandler(OnTraceFinished);
Trace.Write("自定义类别", "自定义跟踪消息");
}
private void OnTraceFinished(object sender, TraceContextEventArgs e)
{
foreach (TraceContextRecord tcr in e.TraceRecords)
{
Response.Write(string.Format(" <li>跟踪类别:{0} 跟踪消息:{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("自定义类别", "自定义跟踪消息")
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>跟踪类别:{0} 跟踪消息:{1}", tcr.Category, tcr.Message))
Next
End Sub
</SCRIPT>
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |