在ASP.NET代码里访问跟踪信息
来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 22:46 点击:次
ASP.NET 2.0允许通过代码在TraceFinished事件里来访问每个请求的跟踪信息。TraceFinished事件是由TraceContext对象引发,用于在收集完所有请求信息后公开跟踪消息。可以利用此事件对跟踪信息进行不同的输出。以下代码就是用程序输出跟踪信息。
C#:
VB.NET:
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>
<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>
<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>
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>