首页 > 编程 > .NET > 正文

在ASP.NET代码里访问跟踪信息

2024-07-10 13:09:40
字体:
来源:转载
供稿:网友
菜鸟学堂:
  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>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表