ASP.Net Health Monitoring and Logging

As you probably know, when it comes to logging there are a lot of application add-ons out there used such as Elmah, nlog and log4net. What you may not know, is ASP.Net has a lot of handy logging features for automatic events straight out of the box ie.

  • Heartbeats
  • Application Lifetime Events
  • Request Processing Events
  • All Errors
  • Infrastructure Errors
  • Request Processing Errors
  • All Audits
  • Failure Audits
  • Success Audits
  • All Events 
  • And Custom Events

By utilizing these events, your application can be configured to handle capturing and logging process diagnostics (e.g. your applications current managed heap size), application life cycle events, application login attempts, server errors etc.

These events can be configured to log to the event viewer or SQL server or the WMI Consumer(for custom applications to monitor).

The setup is pretty basic. Your machine web.config will by default be using Health monitoring to log errors to the event viewer for all server errors and failed login attempts. To extend this, to for example log the heartbeat event for process diagnostic info, add the following lines to the system.web node of your application web.config.

<healthMonitoring enabled="true" heartbeatInterval="10000">

      <rules>

<add name="Process Info" eventName="Heartbeats" provider="EventLogProvider" profile="Default" minInterval="00:01:00"/>

rules>

 

healthMonitoring>

Note: the heart beat interval determines the frequency of the Heartbeats event getting raised.

Now to view the logs, visit the windows ‘event viewer’ and navigate to windows logs -> application as below:

As you can see now have logged a snap shot of this applications current requests executing, requests rejected, managed memory heaps size and more. 

Enjoy!