I want to log execution time of almost all actions in asp.net mvc5 but basically doing this with below code is the correct way or it makes the project very slow ? Any suggestion?
Stopwatch sw = new Stopwatch();
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
sw.Start();
base.OnActionExecuting(filterContext);
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
sw.Stop();
float f = sw.ElapsedMilliseconds;
base.OnActionExecuted(filterContext);
}
I would perhaps store the timing in a appropriately scoped location, perhaps on the request.
that way you avoid using a cumbersome dictionary, and your timer is on a
per request
basis.You can then cast the value in
OnActionExecuted