How to log Windows Service custom logs in C#

In this article, learn how to log windows service custom logs in C# by using EventLog class of System.Diagnostics namespace. By default, all the windows services applications have an ability to interact with the Application event log and write all the relevant log details including exceptions.

How to log Windows Service custom logs in C#?

In the previous article you have seen how to log the custom event logs. In this article, you will learn how to log custom event logs for any windows service applications.

When you create a windows service project, by default logging is turned ON by the windows service project template. Hence, any windows service you will create is having an ability to log event messages such as information, warning and errors into Application event log automatically.

However, you may also want to create custom event logs in order to log the internal exceptions raised from your windows service applications. So, if you want to create and write your own custom event log other than the Application log, you must set the AutoLog property to false. Here is an example of Windows Service code which is self explanatory.

Now, call the EventLog.WriteEntry() function to log the custom event log.

Complete code:

Here is the sample code template that demonstrate custom event logging for Windows Service applications.

– Article ends here –

Recommended:   Install and Uninstall Windows Service using InstallUtil.exe
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