namespace DaemonWorker; public class Worker : BackgroundService { private readonly ILogger<Worker> _logger; public Worker(ILogger<Worker> logger) { _logger = logger; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var time = DateTime.Now; _logger.LogInformation($"Checking for the daemon hour: {time}"); if (time.Hour >= 0 && time.Hour <= 5 || time.Hour >= 21 && time.Hour <= 23) { _logger.LogCritical($"It's time for night of the daemons!: {time}"); _logger.LogWarning($"What a horrible night to have a curse: {time}"); } else { _logger.LogWarning($"The morning sun has vanquished the horrible night: {time}"); } await Task.Delay(5000, stoppingToken); } } }