public partial class Worker : ServiceBase
{
Timer timer;
private int eventId = 1;
EventLog eventLog;
public Worker()
{
InitializeComponent();
eventLog = new EventLog();
if (!EventLog.SourceExists("Alexander"))
{
EventLog.CreateEventSource(
"Alexander", "AlexandersLog");
}
eventLog.Source = "Alexander";
eventLog.Log = "AlexandersLog";
timer = new Timer();
timer.Interval = 5000;
timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
timer.Start();
}
protected override void OnStart(string[] args)
{
eventLog.WriteEntry("Service onStart - final");
}
protected override void OnStop()
{
EventLog.WriteEntry("Service OnStop - final");
}
public void OnTimer(object sender, ElapsedEventArgs args)
{
// TODO: Insert monitoring activities here.
eventLog.WriteEntry("Monitoring the System", EventLogEntryType.Information, eventId++);
}
}