I have made a service in visual studio and imported the eventlog component from the tools. Besides that, I have tweked the code a bit. The service runs fine, starts and stops without error, but it is not detecting new events in the event log despite an attached handler. It shuld see ANY new event in the Windows Application Log, and then write a log entry everytime that says "detected new entry", and also write an entry if the source is backup exec or wsh. I have a vbscript that writes a test event for testing this code. Visual Studio shows no errors. Here is the Code:
private void InitializeComponent()
{
this.eventLog1 = new System.Diagnostics.EventLog();
this.eventLog1.Log = "Application";
this.eventLog1.EnableRaisingEvents = true;
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//
// eventLog1
//
this.eventLog1.EntryWritten += new System.Diagnostics.EntryWrittenEventHandler(this.eventLog1_EntryWritten);
//
// Service1
//
this.ServiceName = "EventMonitor";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
}
private void eventLog1_EntryWritten(object sender, EntryWrittenEventArgs e)
{
eventLog1.WriteEntry("Detected Event");
if (e.Entry.Source == "Backup Exec")
{
eventLog1.WriteEntry("Detected Event: " + e.Entry.Source);
}
if (e.Entry.Source == "WSH")
{
eventLog1.WriteEntry("Detected Event from: " + e.Entry.Source);
}
}
private void InitializeComponent()
{
this.eventLog1 = new System.Diagnostics.EventLog();
this.eventLog1.Log = "Application";
this.eventLog1.EnableRaisingEvents = true;
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//
// eventLog1
//
this.eventLog1.EntryWritten += new System.Diagnostics.EntryWrittenEventHandler(this.eventLog1_EntryWritten);
//
// Service1
//
this.ServiceName = "EventMonitor";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
}
private void eventLog1_EntryWritten(object sender, EntryWrittenEventArgs e)
{
eventLog1.WriteEntry("Detected Event");
if (e.Entry.Source == "Backup Exec")
{
eventLog1.WriteEntry("Detected Event: " + e.Entry.Source);
}
if (e.Entry.Source == "WSH")
{
eventLog1.WriteEntry("Detected Event from: " + e.Entry.Source);
}
}