Alex
Alex

Reputation: 77329

Logging of long/unusual page execution time automatically in ASP.NET

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?

Upvotes: 2

Views: 703

Answers (2)

UpTheCreek
UpTheCreek

Reputation: 32391

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.

Upvotes: 2

Wolfwyrd
Wolfwyrd

Reputation: 15916

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

Upvotes: 3

Related Questions