An application heartbeat is a periodic event which is raised so long as an application is "alive", which can be monitored by one or more listeners which can then act on that heartbeat. This class library demonstrates one way of achieving this, and allows for listeners to be added via the application configuration. (This last is conceptually similar to the way Trace and Debug listeners work.)
The main class is the static Heartbeat class that has a System.Threading.Timer that is initialised the first time the class is referred to, and which raises a "Beat" every second. This beat is then passed on to every listener class (which is a class inheriting from a base HeartbeatMonitorBase) to record or react to as they choose.
The heartbeat listeners collection is read from the application configuration file by the class HeartbeatCustomConfigSection which inherits from the .NET framework 2.0 class System.Configuration.ConfigurationSection, and each class listed in the <heartbeats> section is instantiated when read, by creating a System.Reflection.ConstructorInfo and executing it.
At the start of your application, call the Monitoring.Heartbeat.ResetListensersFromConfig(); method to start the heartbeat and create the listeners per the application configuration file.
The application configuration for the heartbeat listeners should be something like:
<configSections>
<section name ="heartbeatSettings"
type="Monitoring.HeartbeatCustomConfigSection, Monitoring,
Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"/>
</configSections>
And, the individual listeners would be added thus:
<heartbeatSettings>
<heartbeats>
<clear />
<add Name="HeartbeatTrace"
Type="Monitoring.TraceHeartbeatMonitor, Monitoring,
Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
<add Name="HeartbeatTraceTwo"
Type="Monitoring.TraceHeartbeatMonitor, Monitoring,
Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
InitData="foo" />
</heartbeats>
</heartbeatSettings>
| You must Sign In to use this message board. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||