次の方法で共有


Health Monitoring for Application's Lifetime related events in ASP.NET 2.0

The runtime components and controls of ASP.NET 2.0 are instrumented for health monitoring they and raise events for many common situations For ex. failed logins, unhandled exceptions, expired forms authentication tickets, etc . For complete details please visit https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000016.asp.

The best part is that you don't need to churn out too much code to do that. Just add a few lines in your web.config and BOOM, you have done it!

In this post, lets see how we can capture Application's Lifetime related events. You may want to do this in scenarios like sessions getting lost sporadically, monitoring regular health of your application by checking if there are too many Application Start and Shutdown events, etc.

To enable health monitoring in any of your applications, open your web.config file and add the following inside <system.web>...

<healthMonitoring> <rules> <add name="Application Events" eventName="Application Lifetime Events" provider="EventLogProvider" profile="Default" minInterval="00:01:00" /> </rules></healthMonitoring>

Save your web.config file and run your application, view a couple of pages and change the web.config (just add a space and delete the space anywhere in your web.config and save it). We are doing it to ensure that that the AppDomain recycles. Now have a look at your Event Viewer. It should have the following logs...

Event Type: InformationEvent Source: ASP.NET 2.0.50727.0Event Category: Web Event Event ID: 1305Date: 4/13/2006Time: 6:19:30 PMUser: N/AComputer: RAHULSONIDescription:Event code: 1001 Event message: Application is starting. Event time: 4/13/2006 6:19:29 PM Event time (UTC): 4/13/2006 12:49:29 PM Event ID: a01d7c9ff12a43a9baed46f7823f11cd Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: 612d1f6f-4-127894061686875000 Trust level: Full Application Virtual Path: /SendPDF Application Path: K:\My Documents\Visual Studio 2005\WebSites\SendPDF\ Machine name: RAHULSONI Process information: Process ID: 7920 Process name: WebDev.WebServer.EXE Account name: RAHULSONI\Rahul Soni Custom event details: Event Type: InformationEvent Source: ASP.NET 2.0.50727.0Event Category: Web Event Event ID: 1305Date: 4/13/2006Time: 6:19:45 PMUser: N/AComputer: RAHULSONIDescription:Event code: 1002 Event message: Application is shutting down. Reason: Configuration changed. Event time: 4/13/2006 6:19:45 PM Event time (UTC): 4/13/2006 12:49:45 PM Event ID: 1960aa9e549b4d8b9397a3e8c62cd64b Event sequence: 1 Event occurrence: 1 Event detail code: 50004 Application information: Application domain: 612d1f6f-7-127894061605781250 Trust level: Full Application Virtual Path: /SendPDF Application Path: K:\My Documents\Visual Studio 2005\WebSites\SendPDF\ Machine name: RAHULSONI Process information: Process ID: 97456 Process name: VWDExpress.exe Account name: RAHULSONI\Rahul Soni Custom event details:

So, as you can see we can now log Application Lifetime Events. And how many lines of code did we write? Well... it was 9 lines, and I think for logging things like this, Nine is just Fine...

Cheers!Rahul Soni

Comments

  • Anonymous
    April 13, 2006
    Trackback from dotnetkicks.com

  • Anonymous
    June 26, 2008
    Hi, Is there a way to get email notification about app shut down in a case where the app shuts down but does not restart. So, lets say the app does not restart for another ten minutes then how can the admin be emailed about this? The reason being that we dont want emails to be sent out in a case where the app shuts down but restarts right away. We only want the email to be sent out if there is no restart of the app even after waiting ten minutes. Can this be handled via <bufferModes> or <profiles>? Or, we need to create a separate app to handle this ?

  • Anonymous
    March 16, 2009
    Great post.I really like it.Thanks for sharing....