I want to add some logging of how long it takes for a .Net Web Application is taking to process a request.
My idea was to use Application_BeginRequest and Application_EndRequest, I could check HttpContext.Current.Request.Path in Application_BeginRequestand log a start-time and when the same HttpContext.Current.Request.Path goes through Application_EndRequest log the end-time. But with a busy website I could not guarantee that multiple calls would mess this idea up (a call may come in that takes longer to run than an identical call).
So my question is, is there something that I can check in Application_BeginRequest and Application_EndRequest that ties the calls together, is there some ID or something? Or is there something more simple that I could be doing?
My solution for this was to use HttpContext.Current.Items as suggested by ta.speot.is
In Application_BeginRequest I create a System.Diagnostics.Stopwatch and call .Start on it.
Add the Stopwatch to HttpContext.Current.Items.
In Application_EndRequest retrieve the Stopwatch from HttpContext.Current.Items and call .Stop I can now check .Elapsed and that gives me my timings.
When I posted my question I was not aware that HttpContext.Current.Items is specific to a call, but I do now - so this provides the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With