Skip to content

A .NET Worker Windows Service using BackgroundService. Logs Computer Programming Jokes and can send emails.

Notifications You must be signed in to change notification settings

daydin14/JokerService

Repository files navigation

JokerService

System.Text C# Windows Service .NET 8 Serilog Email Service SMTP Microsoft Teams YouTube

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.

Table of Contents

Getting Started

  1. Clone this repository to your local machine.

  2. Build the solution using Visual Studio or the command line:

    dotnet build
  3. To run the project in development using Visual Studio, VS Code, or the command line:

    dotnet run

Features

  • 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.)
  • 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
  • Timer settings to control the interval of the background tasks.
  • Microsoft Teams Channel Integration
  • Export text file with jokes

Publishing

To publish the service as a Windows Service, follow these steps:

  1. Open a command prompt or PowerShell with administrator privileges.

  2. Navigate to the project folder where the service is located.

  3. 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.

  4. Create the Windows Service using the following command:

    sc create JokerService binPath="C:\path\to\your\service\folder\publish\JokerService.dll"
  5. Start the service using:

    sc start JokerService

    This ensures your service is up and running as a Windows Service.

Credits

Version History

  • 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

About

A .NET Worker Windows Service using BackgroundService. Logs Computer Programming Jokes and can send emails.

Topics

Resources

Stars

Watchers

Forks

Languages