Fetch event log details from event viewer in C#

Handing the exception and logging is very important requirement of any application. There are different options to achieve this but the one which I have used  mostly  is Microsoft Enterprise Exception Handling and Logging Library. It’s very handy and easy to use. We can store the exceptions details in various formats like text, XML file or system event log.

Now in case when we store exceptions in the system event log, we need to construct viewer page where admin user can see the exceptions thrown in the application and pass that information to the development team. Here we need to fetch exception log details from the system event log of server.

To achieve this there is inbuilt method EventLog.GetEventLogs available in the C# but if we have thousands of events on the system event log then it will take significant amount of time to fetch event log detail. To avoid the performance issue, It is advisable to use EventLogQuery  and EventLogReader classes to fetch only small set of event logs based on the filter criteria like Source, Datetime etc..

Refer following article for more technical details on how to implement this approach.

http://www.c-sharpcorner.com/UploadFile/d551d3/reading-and-querying-eventviewer-efficiently-with-C-Sharp/

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s