Member-only story
Create a Windows Service App in .NET Core

In this blog post, we will create a demo Windows Service application which includes a set of features such as reading configurations, logging to files, dependency injection, file system watcher, and so on. The application will be written in .NET Core 3, which includes new concepts like generic host, worker service, background service, and so on. We will go over the installation process of our Windows Service application as well.
The complete solution can be found in this GitHub repository. This application can be used as a bare-bones template for Windows Service applications or Console applications.
Why do we build Windows Service applications?
Microsoft Windows services allow us to create long-running executable applications that run in their own Windows sessions. Windows services don’t have any user interface, can be automatically started when the computer reboots, and can be paused and restarted.
Windows services are ideal for long-running functionality that does not interfere with other users who are working on the same computer. For example, in a Windows Service application, we can use a FileSystemWatcher
to listen to the file system change notifications and raise events when a directory, or a file in a directory, changes. The beauty is that the Windows Service application handles all the events in the background.
Practically, we usually run services in the security context of a specific user account that is different from the logged-on user or the default computer account. So a hacker cannot easily mess up the file system or the service related database through a compromised computer.
If you have created a Windows Service application in .NET framework, then you must remember the pain of debugging the Windows Service application. During those old days, the tool TopShelf helped us a little bit, but not much. Now, with .NET Core 3, the experience of developing a Windows Service application is much more pleasant. In my opinion, the concept of a Windows Service is clearer as well.
In order to follow along, you need to have .NET Core 3+ SDK installed. Also, you need to have Admin privileges in your computer or the hosting server, so that you can install the Windows…