Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Service to detect new event log entries

Status
Not open for further replies.

BoostMR2

IS-IT--Management
Jul 20, 2007
33
0
0
US
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);
}
}

 
Update:

My end goal was to write to a log file so I could import the results to another app. The write to file works great. So the event handling is woring. Just can't figure out why I can't write to eventLog1. If anyone has an idea let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top