views:

44

answers:

2

Hello everyone,

in order to estimate the execution time of the requests sent to my mvc applications, i've been using log4net to log the time elapsed in the EndRequest event of global.asax for my MVC application. However, the EndRequest is called for every request, including the resources (css, images); i'd prefer to be able and distinguish between the two kinds of requests.

Is there a way to separate routed requests from static content requests? Should i abandon this hooking spot and time the execution at another point in the code?

+1  A: 

Check out Phil Haack's Route Debugger.

Martin
This one is a pure gold. :)
Arnis L.
If i'm following the Phil Haack's code, what he does is:- register the routes- overwrite every route handler with one that returns a specific httphandler, which then returns the hardcoded html page on every requestI don't really see how i'm supposed to hook the execution time logging in there. What i could do is:- create a httphandler that logs begin and end requests- replace the routehandler in each concerned route by a routehandler that hands out the logging httphandlerbut it hardly seems worth the hassle since i can do what mookid suggested below... am i missing something?
samy
sorry about the terrible formatting above, the textarea ate my breaklines...
samy
+1  A: 

I usually derive all my controller from a ControllerBase class, into which I insert the necessary logging in the OnActionExecuting and OnActionExecuted method overrides.

This gives me one central place to put the logging for all my controller actions + more stuff that usually would have piled up in all my action methods throughout all my controllers.

mookid8000
i didn't want to do this at first, but it really is the road with less friction at this point in the project
samy
it has got to be the easiest and most pragmatic way of achieving what you want... of course some people might feel that the logging is intrusive because now it is part of every controller, but then you could just add the code to an action attribute instead and put the attribute on the base controller
mookid8000