views:

391

answers:

2

On ASP.NET MVC Preview 5, we're having trouble getting any trace messages from Global or Controllers to appear in either a page (View) or Failed Request Tracing (FREB).

Neither of these calls work in a Controller Action:

HttpContext.Trace.Write("hello");
System.Diagnostics.Trace.WriteLine("world");

There are no issues with trace statements in a Page's code-behind; those messages appear correctly.

+2  A: 

Those calls happen before the Page (ViewPage) is even created so you need to enable tracing in Web.config as well as in the page.

In Web.config, directly within the node add:

<trace enabled="true" />

You have two options to view the trace. You can enable it in your view within the @Page declaration.

<%@ Page ... Trace="true" %>

Or you can navigate to /trace.axd

Note that we did have a bug with this, but I don't remember when it was fixed. I tried this with the Beta, not with Preview 5.

Haacked
Thanks, Phil - but I don't think this will work for us. It's a bad idea to turn tracing on in production, correct?
Jarrod Dixon
A: 

In MVC2 .NET 4.0, I also cannot get Trace to work when called from a View.

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

The traces I write from the Controller

System.Diagnostics.Trace.WriteLine("Message from Controller");

Go into the http://localhost:port/trace.axd log just fine.

Turning Trace="true" in the Page Directive does not help.

Isn't

supposed to work for Views also?

Thanks.

AUSTX_RJL
Maybe you should post this as a new question.
UpTheCreek