I'm trying to read event logs for my application EventLoggingApp. The problem is reading logs for my single source (EventLoggingApp).
This code read logs for every source. What is the problem? Any advice?
static void ReadEvenLog() { string eventLogName = "Application"; string sourceName = "EventLoggingApp"; string machineName = "Tom"; EventLog eventLog = new EventLog(); eventLog.Log = eventLogName; eventLog.Source = sourceName; eventLog.MachineName = machineName; foreach (EventLogEntry log in eventLog.Entries) { Console.WriteLine("{0}\n",log.Source); } }
Right click on the Start button and select Control Panel > System & Security and double-click Administrative tools. Double-click Event Viewer. Select the type of logs that you wish to review (ex: Application, System)
You can do this when you start an application by opening the shortcut menu for the application (if you're using a mouse, right-click the application icon) and indicating that you want to run as an administrator. You can use EventLog to create custom event logs that you can view through the server's Event Viewer.
Runs a query to retrieve events from a channel or log file that match the specified query criteria.
The WriteEntry method writes the given string directly to the event log; it does not use a localizable message resource file. Use the WriteEvent method to write events using a localized message resource file.
Try this:
EventLog log = new EventLog("Security"); var entries = log.Entries.Cast<EventLogEntry>() .Where(x => x.InstanceId == 4624) .Select(x => new { x.MachineName, x.Site, x.Source, x.Message }).ToList();
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