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
Actually, now this can be done. Using glimpse, you can return and use Trace.Write in MVC.
http://getglimpse.com/
Only for ASP.NET MVC 3.0 and up
You could try to use Html.Action to get the controller to do the tracing for you. For example, if you need to trace the error from the default Error view, you can use
Html.Action("TraceError", "Error", new { ControllerName = Model.ControllerName, ActionName = Model.ActionName, Exception = Model.Exception })
Then inside your Error Controller, implement the method
public ActionResult TraceError(String ControllerName, String ActionName, Exception Exception)
{
System.Diagnostics.Trace.TraceError("Error Message: {0}", Exception.Message);
// Other tracing statements
}
Instead of using the HttpContext.Current.Trace or the System.Diagnostics.Trace, try using the Controller.HttpContext.Trace ?
The quote doesn't apply to tracing in filters and actions. Even then, it doesn't apply as you can get trace output from OnResultExecuting. It's only OnResultExecuted where it's too late to get trace output.
I was only able to get integrated trace output to work in IIS 7.5 by running my MVC 3 application in Cassini - then integrated tracing started working in IIS 7.5.
I'm investigating some trace anomolies in MVC
Quoting directly from the book "MVC 2 in action":
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. You might try to leverage the TraceContext class in your controller, but these statements won’t ever make their way to the list of messages in the trace log (on your page or on Trace.axd). Instead, you can use System.Diagnostics.Trace and set up your own TraceListeners to inspect the activity in your controllers. Alternatively, you can leverage a more mature logging framework such as log4net or NLog:
You debug ASP.NET MVC applications just as you would any .NET application. Tracing, however, doesn’t offer as much for MVC. Instead, you can lean on the built-in TraceListeners in .NET, or utilize a good logging library like those mentioned earlier. Another aspect of error logging is health monitoring.
Sorry for not answering in my own words, but I think this explanation is spot on :)