This repository contains the source code for a sample Windows Service created using .NET 8. The service demonstrates how to set up a basic worker service, integrate with the Windows Service Control Manager (SCM), and implement logging using Serilog.
- Clone the repository
git clone https://github.com/tivole/sample-windows-service.git
- Navigate to the project directory
cd sample-windows-service
- Build the project
dotnet build
- Publish the project
dotnet publish -o ./publish -c Release -p:PublishSingleFile=true
- Install the service using
sc.exe
:
sc create SampleService binPath= "C:\\path\\to\\publish\\SampleService.exe"
- Start the service:
sc start "SampleService"
- Stop the service:
sc stop "SampleService"
Check the sample-service.log
file in the publish
folder for log entries indicating the service is running.