You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
In MVC app - Trace statement put in part of a controller action is NOT showing up if an exception is occured say like divide by zero exception in one of the actions
#1004
Open
arulmoli opened this issue
Jul 20, 2017
· 0 comments
I am trying to write a "trace" statement AFTER an exception had occurred. For example in a controller i am overriding the "protected override void OnException(ExceptionContext filterContext)" function and i simply put a trace statement. To simulate an exception, inside an action in that controller where i am overriding the "OnException" function, i just try to divide a number by 0, so that it will throw an exception and i see the exception getting routed to "OnException" handler.
After that, I don't see that in "Glimpse-Trace" tab. Does anyone know what might be happening? I do see the normal traces that i put in before any exception occurs. Thank you!
My sample code:
Note, i called the action below called "GetAwardsLeadershipPage" using an ajax call from a razor view.
public class MembersPortfolioController : Controller
{
protected override void OnException(ExceptionContext filterContext)
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// Write to log until i figure a way out on how to show the exception.
// Write to Trace later and install Glimpse where youc an see the exceptions on the client side.
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_log != null)
{
string errMsg = string.Format("[{0}][{1}]: Exception:{2} StackTrace={3}",
filterContext.RouteData.Values["controller"].ToString(),
filterContext.RouteData.Values["action"].ToString(),
filterContext.Exception.Message,
filterContext.Exception.StackTrace);
// For Glimpse to catch "System.Diagnostics.Trace" and display it in Glimpse's view - this will
// be useful when we want to debug what's happening on the server side from the browser
//itself (without logging into production machine).
Trace.Write(errMsg);
}
}
public ActionResult GetAwardsLeadershipPage()
{
Trace.Write("Before divide by zero");
// To simulate divide by zero exception.
int result = 100 / int.Parse("0");
return PartialView("_AwardsLeadership", null);
}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am trying to write a "trace" statement AFTER an exception had occurred. For example in a controller i am overriding the "protected override void OnException(ExceptionContext filterContext)" function and i simply put a trace statement. To simulate an exception, inside an action in that controller where i am overriding the "OnException" function, i just try to divide a number by 0, so that it will throw an exception and i see the exception getting routed to "OnException" handler.
After that, I don't see that in "Glimpse-Trace" tab. Does anyone know what might be happening? I do see the normal traces that i put in before any exception occurs. Thank you!
My sample code:
Note, i called the action below called "GetAwardsLeadershipPage" using an ajax call from a razor view.
The text was updated successfully, but these errors were encountered: