How to read event logs with folders?

I want to programmatically get an event log that appears in a folder in eventvwr. This is for Windows 8 Apps: Microsoft-Windows-AppHost / Admin. I work as admin.

This does not work:

System.Diagnostics.EventLog.SourceExists("Microsoft-Windows-AppHost/Admin"); 

This doesn't work either:

 EventLogQuery queryMicrosoftWindowsAppHost = new EventLogQuery("Microsoft-Windows-AppHost/Admin", PathType.LogName); _eventsMicrosoftWindowsAppHost = new List<EventRecordWrittenEventArgs>(); _eventLogWatcherMicrosoftWindowsAppHost = new EventLogWatcher(queryMicrosoftWindowsAppHost); _eventLogWatcherMicrosoftWindowsAppHost.EventRecordWritten += (object sender, EventRecordWrittenEventArgs e) => { _eventsMicrosoftWindowsAppHost.Add(e); }; _eventLogWatcherMicrosoftWindowsAppHost.Enabled = true; 
+4
source share
1 answer

You can read the event log using this code:

 EventLogReader reader = new EventLogReader("Microsoft-Windows-AppHost/Admin"); var evt = reader.ReadEvent(); while (evt!= null) { // Write the message to the console Console.WriteLine(evt.FormatDescription()); evt = reader.ReadEvent(); } 

If you want to attach a handler, your code will be close, but you can just pass the string to the observer instead of using the request object:

 var watcher = new EventLogWatcher("Microsoft-Windows-AppHost/Admin"); watcher.EventRecordWritten += (object s, EventRecordWrittenEventArgs e1) => { Console.WriteLine(e1.EventRecord.FormatDescription()); }; watcher.Enabled = true; 
+2
source

All Articles