This repository contains a .NET Worker Windows Service implementation using BackgroundService
. The service performs background tasks and demonstrates how to create a long-running service in a Windows environment by logging Computer Programming Jokes.
-
Clone this repository to your local machine.
-
Build the solution using Visual Studio or the command line:
dotnet build
-
To run the project in development using Visual Studio, VS Code, or the command line:
dotnet run
- Long-running Windows Service using
BackgroundService
. - Background tasks and worker logic.
- Logging Computer Programming Jokes with
Serilog
to the current directory.- (Creates a
Logs
folder in the project's root directory.)
- (Creates a
- Email Service to send the jokes to the specified email address.
- Email settings are configurable in the
appsettings.json
file. - Email settings include the SMTP server, port, email address, and password.
- Tested with Smtp4Dev. https://github.com/rnwood/smtp4dev
- Email settings are configurable in the
- Timer settings to control the interval of the background tasks.
- Microsoft Teams Channel Integration
- Export text file with jokes
To publish the service as a Windows Service, follow these steps:
-
Open a command prompt or PowerShell with administrator privileges.
-
Navigate to the project folder where the service is located.
-
Use the following command to publish the service:
dotnet publish -c Release -o ./publish
This command creates a 'JokerService.dll' in the
./publish
directory, which acts similarly to 'JokerService.exe' on Windows. -
Create the Windows Service using the following command:
sc create JokerService binPath="C:\path\to\your\service\folder\publish\JokerService.dll"
-
Start the service using:
sc start JokerService
This ensures your service is up and running as a Windows Service.
-
This project is inspired by the tutorials from:
- Version [1.0.2.0]
- Added Export Service to export jokes to a text file.
- Refactored Worker Service so its' processes and other service calls are split into separate classes.
- Version [1.0.1.2]
- Refactored Serilog Configuration to separate class within Settings\ directory.
- Renamed SmtpSettings to EmailSettings and made calls configurable
- Added XML Documentation Comments.
- Version [1.0.1.1]
- Updated Serilog Configuration
- Added TimersSettings
- WIP MS Teams Sink Integration
- Version [1.0.1.0] Added Email Service
- Version [1.0.0.1] Minor CleanUp and Refactoring
- Version [1.0.0.0] Original Release