Creating EventLog in C#

In C#, the System.Diagnostics namespace of System.Runtime.dll has the EventLog class which can be used to write a application log entry into the windows event logs.

Creating EventLog in C#:

As you are already aware, the Windows Event Viewer shows a log of application and system messages which includes errors, information messages, and warnings. It’s one of the most frequently used tool for troubleshooting all kinds of different Windows problems.
The following example demonstrates how to use the EventLog class to log the information, warning and error messages into windows event logs.

Note: Always make sure that run the application in Administrator mode in order to log the messages in windows event logs. Otherwise your application may encounter security exception.

After executing the above code, you can see the log messages logged in event log viewer.

– Article ends here –

Recommended:   Measure the code execution time using Stopwatch instance in C#
Share this:

Kiran is a Software engineer by profession and Enthusiastic blogger, love to write articles on computer technology and programming. Reach him at

We will be happy to hear your thoughts

Leave a reply

Shopping cart