Iis – Write to Windows Event Log when an IIS site is started or stopped

iisiis-7.5windows-event-log

Can I configure IIS 7.5 to write to the Windows Event Log whenever one of the sites on the web server is started or stopped? For example when someone starts/stops a site via the IIS Manager user interface.

I know I can configure the Application_On{Start,End} for each of the web sites to write a custom message to the Windows Event Log, but I'm just wondering whether there's something built-in already. I also know about activating the logging of App Pool recycling, but that's not the same thing as starting/stopping a site, especially if more than one site is sharing the same App Pool.

In particular it would be very helpful if it listed the name of the user who started/stopped the site.

One thing I already tried was enabling logging to the IIS-Configuration>{Administrative, Operational} event logs, but unfortunately nothing appears there when starts / stops take place.

Best Answer

A couple of things. When I enable the Microsoft-Windows-IIS-Configuration/Operational event log, I do get events when the site is started or stopped. I get "Verbose" event 29 with this content:

Changes to '/system.applicationHost/sites/site[@name="Default Web Site" and @id="1"]/@state' at 'MACHINE/WEBROOT/APPHOST' have successfully been committed.

This is on Server 2008 R2. Now this doesn't tell you whether the site is started or stopped, but merely indicates that it changed status. Could be helpful if you monitor that log.

A long while back I wrote this: http://www.eventsentry.com/blog/2010/02/how-to-really-monitor-smtp-pop.html. It was a VBScript which would enumerate the virtual directories in IIS and tell you when one of them was stopped. This works on 2003, but unfortunately not on 2008. May be a starting point, I'll revisit this at some point so we can update the script.

Not the answer, but may get you closer to what you are trying to achieve. You'll most definitely will need some script (which is maybe trigger by the above event) which will enumerate the sites and their status.