0
votes

I want to read logs from event viewer folders which are in "Applications and Services Logs" but I cannot found those folders in C#.

Below is my code:

if (EventLog.Exists("MyApp-Folder1-Folder2/General"))
{
    EventLog log = new EventLog("MyApp-Folder1-Folder2/General");
    log.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
    log.EnableRaisingEvents = true; 
}

If the log is found, I want to set watcher on that folder. The above path exists inside "Applications and Services Logs" but still EventLog.Exists() returns false.

How can I read such logs in C#?

1
You might need to check if the Source exists via EventLog.SourceExists - Jehof

1 Answers

0
votes

Not sure what OS you're using, but on my Windown 8, you can find the logs in the following directory:

C:\Windows\System32\winevt\Logs

there you have them with a .evtx extension. The problem is:

EVTX files are Microsoft Event Viewer logs that can be viewed using Event Viewer. To launch Event Viewer hold Windows Button whilst pressing R and then type eventvwr.msc in Run window.

I'm not sure you can directly read them. Seems you can export them, but that's not what you want if i understand you correctly.