Question on logging and performance measurement best practices.
When trying to do performance logging, I've discovered that there is a timing delay if you start your timer at OnActionExecuting
vs Application_BeginRequest
. It was off by 40% in some cases, which is significant (This is with MVC 4 Web API). I'm looking for best practices as far as insertion points of various monitoring code, including performance monitoring, and a good place at which to write the log at the end.
A framework like MiniProfiler (http://miniprofiler.com/) instructs people to use Application_BeginRequest
and Applicaiton_EndRequest
, but this is deemed as "ugly" by some professionals in the forums (PS Why?).
Is there a non-ugly way to accurately get the full timing of a request? Thanks.
I have seen the following suggested:
- Application_BeginRequest
- OnActionExecuting (ActionFilter)
- OnAuthorization (ActionFilter)
- HttpModule with an edit in Web.config as described here
- DelegatingHandler (Web API audit logging)
Perhaps DelegatingHandler
is the best one I have seen suggested, as it takes place before routing. My only concern is that a lot of official Microsoft blogs and pros have recommended the ActionFilters instead, so perhaps I'm missing something here.
Currently I'm using Application_BeginRequest
(because its easy) to start the counter and am modifying a global variable if a real route was found at OnActionExecuting
. Back at Application_EndRequest
I check if a route was found and then log accordingly, not logging other http requests like "/favicon.ico" which apparently show up at Applicaiton_BeginRequest
.