ASP.NET MVC跟踪问题 [英] ASP.NET MVC Tracing Issues
问题描述
我如何得到ASP.NET MVC跟踪信息保持一致为页跟踪输出的trace.axd?我可能只是缺少明显的东西,请拨打它,如果你看到它。
How do I get ASP.NET MVC trace information to be consistent for in-page trace output as trace.axd? I may just be missing something obvious, please call it out if you see it.
所以,早在常规ASP.NET日子里,你可以简单地添加以下到你的web.config:
So back in the regular ASP.NET days, you could simply add the following to your web.config:
<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</listeners>
</trace>
</system.diagnostics>
...
<system.web>
<trace enabled="true" pageOutput="true" writeToDiagnosticsTrace="true"/>
...
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="1" compilerOptions="/d:TRACE" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
然后,你可以添加以下内容在页面:
Then you could add the following in your pages:
HttpContext.Current.Trace.Write("Write Trace Here");
or
System.Diagnostics.Trace.Write("Write Trace Here");
如果你打你的页面(即本地主机:61115 / Default.aspx的),你会得到一个不错的跟踪表嵌有asp.net页面事件自定义曲线:
And if you hit your page (i.e. localhost:61115/Default.aspx), you would get a nice trace table with your custom trace embedded with asp.net page events:
aspx.page Begin Load 0.00343 0.000357
test 0.00462176 0.001192
aspx.page End Load 0.00526904 0.000018
击中本地主机?:61115 /的trace.axd ID = 0将保留相同的跟踪结果作为在页跟踪输出
Hitting localhost:61115/Trace.axd?id=0 would retain the same trace results as the in-page trace outputs.
不幸的是,我不能让这个在ASP.NET MVC 2.0工作,原因不明给我。我使用类似的web.config设置上面列出的。有趣的是,我只能拿痕迹部分工作。所以,如果我打的功能相当于默认页面(也就是我的HomeController索引操作方法),我看到所有的传统asp.net页面事件,如preINIT,preLOAD,prerender等,但不无论是使用System.Diagnostics程序自定义跟踪味精也不HttpContext.Trace.Write。
Unfortunately, I cannot get this to work in ASP.NET MVC 2.0 for reasons unknown to me. I use similar web.config settings as ones listed above. What is interesting is that I can only get traces to partially work. So if I hit the functionality equivalent default page (aka index action method of my homecontroller), I see all of the traditional asp.net page events such as preinit, preload, prerender, etc but no custom trace msg using either System.Diagnostics nor HttpContext.Trace.Write.
不过,如果我转向的trace.axd?ID = 0的文件,我招呼着我的自定义跟踪消息,但没有ASP.NET页面事件跟踪输出。我必须在这里失去了一些东西,是造成这种不一致的跟踪信息我在页面中看到对的trace.axd(回想一下传统的asp.net输出在页面与相同输出的trace.axd)。我真的想有我与的trace.axd一致的页跟踪信息(无论是通过去除传统的asp.net页面事件或其他方式)。有我丢失的东西?
However, if I turn to the Trace.axd?id=0 file, I'm greeted with my custom trace messages but no ASP.NET page event trace output. I must be missing something here that is causing this inconsistency in trace information I see in-page vs. trace.axd (recall that traditional asp.net outputs identical in-page vs. trace.axd outputs). I would really like to have my in-page trace information consistent with trace.axd (either by removing the traditional asp.net page events or other means). Is there something I am missing?
推荐答案
其实,现在可以做到这一点。使用惊鸿一瞥,您可以返回,并在MVC中使用Trace.Write。
Actually, now this can be done. Using glimpse, you can return and use Trace.Write in MVC.
仅限于ASP.NET MVC 3.0及
Only for ASP.NET MVC 3.0 and up
这篇关于ASP.NET MVC跟踪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!