I'm trying to retrieve some event log in a category that is different from Application. For example, I want to get the info in "Microsoft-Windows-Application Server-Applications/Operational". Below it is my code
EventLog log = new EventLog("Microsoft-Windows-Application Server-Applications/Operational");
int index = log.Entries.Count - 1;
Debug.WriteLine(log.Entries[index].Message);
But it always shows the error:
The event log 'Microsoft-Windows-Application Server-Applications/Operational' on computer '.' does not exist.
If I simply use "Application", then I can get the log in Application category.
How to get log for "Microsoft-Windows-Application Server-Applications/Operational"?
Thanks

The EventLog class only lets you access Windows event logs. You will want to use instead the EventLogReader found in System.Diagnostics.Eventing.Reader namespace.
EventLogQuery query = new EventLogQuery("Microsoft-Windows-Application Server-Applications/Operational", PathType.LogName, "*");
EventLogReader reader = new EventLogReader(query);
EventRecord eventRecord;
while ((eventRecord = reader.ReadEvent()) != null)
{
Console.WriteLine(String.Format("{0} - {1}",
eventRecord.TimeCreated,
eventRecord.FormatDescription()));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With