Hi,
I get the source code below from one of Microsoft's page. But it has lots
of bugs in it, and I can not compile it. Can someone please correct the code
and make it work as this:
- the code will listen the event log and when there is a new event, it will
write event details to the command line...
regards,
atx
----------------------------------------------------------------------
// This code demonstrates how to monitor the NT event log for
// the arrival of new events
using System.Management;
WQLEventQuery q = new WQLEventQuery("InstanceCreationEvent",
"TargetInstance ISA 'Win32_NTLogEvent'")
// Watch for NT Events in the NTEventLog
ManagementEventWatcher w = new ManagementEventWatcher(q);
w.EventArrived += h.EventArrived;
w.Start();
Ã,Â.
w.Stop();
// Define the event handler
public void EventArrived(Object sender, EventArrivedEventArgs e)
{
//Get the Event object and display it
Console.WriteLine("NTEvent "+e.Event["Message"]");
}
--------------------------------------------------------------------------