概述
Enabling Tracing
<%@ Page Trace=
"
true
" ...
%>
or
protected
void Page_Load(Object sender, EventArgs e)
{
Trace.IsEnabled = true;
}
{
Trace.IsEnabled = true;
}
By default, trace messages are listed in the order they were written by your code. Alternatively, you
can specify that messages should be sorted by category using the TraceMode attribute in the
Page directive:
<%@ Page Trace=
"
true
" TraceMode=
"
SortByCategory
"
%>
or the TraceMode property of the Trace object in your code:
Trace.TraceMode = TraceMode.SortByCategory;
Writing Trace Information
protected
void cmdWrite_Click(Object sender, EventArgs e)
{
Trace.Write( " About to place an item in session state. ");
Session[ " Test "] = " Contents ";
Trace.Write( " Placed item in session state. ");
}
{
Trace.Write( " About to place an item in session state. ");
Session[ " Test "] = " Contents ";
Trace.Write( " Placed item in session state. ");
}
or uses overloaded method:
protected
void cmdWriteCategory_Click(Object sender, EventArgs e)
{
Trace.Write( " cmdWriteCategory_Click ",
" About to place an item in session state. ");
Session[ " Test "] = " Contents ";
Trace.Write( " cmdWriteCategory_Click ",
" Placed item in session state. ");
}
{
Trace.Write( " cmdWriteCategory_Click ",
" About to place an item in session state. ");
Session[ " Test "] = " Contents ";
Trace.Write( " cmdWriteCategory_Click ",
" Placed item in session state. ");
}
Trace an exception
protected
void cmdError_Click(Object sender, EventArgs e)
{
try
{
DivideNumbers( 5, 0);
}
catch (Exception err)
{
Trace.Warn( " cmdError_Click ", " Caught Error ", err);
}
}
private decimal DivideNumbers( decimal number, decimal divisor)
{
return number/divisor;
}
{
try
{
DivideNumbers( 5, 0);
}
catch (Exception err)
{
Trace.Warn( " cmdError_Click ", " Caught Error ", err);
}
}
private decimal DivideNumbers( decimal number, decimal divisor)
{
return number/divisor;
}
Application-Level Tracing
To enable application-level tracing, you need to modify settings in the web.config file, as
shown here:
<
configuration
>
< system.web >
< trace enabled ="true" requestLimit ="10" pageOutput ="false" />
...
</ system.web >
</ configuration >
< system.web >
< trace enabled ="true" requestLimit ="10" pageOutput ="false" />
...
</ system.web >
</ configuration >
To view tracing information, you request the trace.axd file in the web application’s root directory. This file doesn’t actually exist; instead, ASP.NET automa tically intercepts the request and interprets it as a request for the tracing information. It will then list the most recent co llected requests, provided you’re making the request from the local machine or have enabled remote tracing
转载于:https://www.cnblogs.com/JasonBie/archive/2012/04/11/2442568.html
最后
以上就是专一钢笔为你收集整理的Page Tracing Enabling Tracing的全部内容,希望文章能够帮你解决Page Tracing Enabling Tracing所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复