ASP.NET跟踪是否适用于MVC2视图?

时间:2022-08-26 21:29:24

I have a VS 2010 MVC2 .NET 4.0 web application. ASP.NET tracing is enabled both in the Page directive (Trace="true) and in the Web.config:

我有一个VS 2010 MVC2 .NET 4.0 Web应用程序。在Page指令(Trace =“true)和Web.config中都启用了ASP.NET跟踪:

<trace enabled="true" 
       requestLimit="10"
       pageOutput="true"
       traceMode="SortByTime" 
       localOnly="true" 
       writeToDiagnosticsTrace="true"
       />

A standard trace listener is also configured in the Web.config:

Web.config中还配置了标准跟踪侦听器:

<trace autoflush="true" indentsize="4">
  <listeners>
    <add name="WebPageTrace" type="System.Web.WebPageTraceListener, System.Web, Version=4.0.30319.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <add name="TextWriterTrace" type="System.Diagnostics.TextWriterTraceListener" initializeData="textListener.log" />
  </listeners> 
</trace>

Tracing works fine from the controller, but when I add a Trace in the View (.aspx) nothing ever shows:

跟踪在控制器中运行良好,但是当我在视图(.aspx)中添加跟踪时,没有任何显示:

<% System.Diagnostics.Trace.WriteLine("Message System.Diagnostics.Trace from View"); %>
<% Page.Trace.Write("Message Page.Trace from View"); %>

Is this supposed to work? Is there something else that is needed to enable Tracing from a View?

这应该有用吗?从视图启用跟踪是否还需要其他东西?

Thanks

1 个解决方案

#1


1  

I believe this was answered by this question. Here was just a bit of the answer provided...

我相信这个问题得到了回答。这里只是提供了一些答案......

When you called Trace.Write() in Web Forms, you were interacting with the Trace- Context class. This exists on your ViewPage in ASP.NET MVC, but this isn’t where you would want to write tracing statements. By the time you’ve passed the baton over to the view, there’s no logic there that you’d need to trace. Instead, you’d like to trace the logic embedded in your controllers

在Web窗体中调用Trace.Write()时,您正在与Trace-Context类进行交互。这存在于ASP.NET MVC中的ViewPage上,但这不是您想要编写跟踪语句的地方。当你将指挥棒传递给视图时,那里没有你需要跟踪的逻辑。相反,您希望跟踪控制器中嵌入的逻辑

#1


1  

I believe this was answered by this question. Here was just a bit of the answer provided...

我相信这个问题得到了回答。这里只是提供了一些答案......

When you called Trace.Write() in Web Forms, you were interacting with the Trace- Context class. This exists on your ViewPage in ASP.NET MVC, but this isn’t where you would want to write tracing statements. By the time you’ve passed the baton over to the view, there’s no logic there that you’d need to trace. Instead, you’d like to trace the logic embedded in your controllers

在Web窗体中调用Trace.Write()时,您正在与Trace-Context类进行交互。这存在于ASP.NET MVC中的ViewPage上,但这不是您想要编写跟踪语句的地方。当你将指挥棒传递给视图时,那里没有你需要跟踪的逻辑。相反,您希望跟踪控制器中嵌入的逻辑