2011-05-03 118 views
2

在ASP.NET MVC 3应用程序中,从父控制器方法(或调用的业务对象)调用HttpContext.Trace.Write和System.Diagnostics.Trace.Write会导致Trace.axd中的条目。为什么跟踪在ASP.NET MVC子操作中不起作用?

如果父视图调用子动作,例如, Html.RenderAction(“ChildAction”),则ChildAction Controller方法内的跟踪语句不会反映在Trace.axd中。 但是,如果我直接点击http://localhost/Home/ChildAction,则语句确实会出现在跟踪中。

我做错了什么,或者是否有一些网站配置需要允许跟踪为孩子行为和他们所调用的任何业务方法?

HomeController.cs:

public ActionResult Index() 
{ 
    HttpContext.Trace.Write("blah"); 
    System.Diagnostics.Trace.WriteLine("blah diag"); 
    var b = new Business(); 
    b.DoStuff(); 
    return View(); 
} 

public ActionResult ChildAction() 
{ 
    HttpContext.Trace.Write("child action trace"); 
    System.Diagnostics.Trace.WriteLine("child action diag"); 
    var b = new Business(); 
    b.DoStuff(); 
    return Content("some content"); 
} 

Index.cshtml:

<h2>Index</h2>
@{ Html.RenderAction("ChildAction"); }

web.config中:

<trace enabled="true" localOnly="false" mostRecent="true" pageOutput="false" requestLimit="1000" traceMode="SortByTime" writeToDiagnosticsTrace="false" />

<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</listeners>
</trace>
</system.diagnostics>

回答

0

DGreen,也许你可以尝试使用掠影(website)。它有它自己的TraceListener实现,可以为你解决这个问题。