ASP.NET MVC Tracing Issues

后端 未结 5 802
暖寄归人
暖寄归人 2021-02-05 08:20

Question

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

5条回答
  •  时光取名叫无心
    2021-02-05 08:52

    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
    }
    

提交回复
热议问题