views:

169

answers:

2

Hello,

I'd like to implement some kind of automatic "logging" in my ASP.NET MVC application when a page execution (incl. database calls etc.) takes longer than 3 seconds, and then gather some 'circumstantial evidence', e.g. which action was called, what the parameters were, session information etc. so I can then store that info for review/send it via email and so forth.

How could I do this, preferably on a global level without editing/adding code to each of my many controller actions?

Your input is very much appreciated!

+2  A: 

Start by looking at the global.asax methods that hook into the following events:

-- Application_BeginRequest

-- Application_EndRequest

Record the time in the fist, compare it to current time in the last - if it's too long log it. You can probably get the action etc from the HttpContext.Current.

UpTheCreek
+3  A: 

BeginRequest and EndRequest in global.asax is the most basic way, record a start and end time then log from there. Another (more reusable) way may be to create your own custom provider such as demonstrated on MSDN

Wolfwyrd