From 0f479a026822fd8e09ddd5f971622bd803856cd2 Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Fri, 20 Feb 2026 22:48:07 +0100 Subject: [PATCH] Added Debug logging sink --- Cajetan.OF-DL/Cajetan.OF-DL.csproj | 1 + Cajetan.OF-DL/ProgramCajetan.cs | 2 +- ...ingService.cs => CajetanLoggingService.cs} | 22 +++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) rename Cajetan.OF-DL/Services/{SeqLoggingService.cs => CajetanLoggingService.cs} (67%) diff --git a/Cajetan.OF-DL/Cajetan.OF-DL.csproj b/Cajetan.OF-DL/Cajetan.OF-DL.csproj index 0e0fd7d..a26ab39 100644 --- a/Cajetan.OF-DL/Cajetan.OF-DL.csproj +++ b/Cajetan.OF-DL/Cajetan.OF-DL.csproj @@ -31,6 +31,7 @@ + diff --git a/Cajetan.OF-DL/ProgramCajetan.cs b/Cajetan.OF-DL/ProgramCajetan.cs index 2bfa3b0..13e1f06 100644 --- a/Cajetan.OF-DL/ProgramCajetan.cs +++ b/Cajetan.OF-DL/ProgramCajetan.cs @@ -20,7 +20,7 @@ static async Task ConfigureServices(string[] args) { // Set up dependency injection with LoggingService and ConfigService ServiceCollection services = new(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(new ExitHelper(new SpectreDownloadEventHandler())); ServiceProvider tempServiceProvider = services.BuildServiceProvider(); diff --git a/Cajetan.OF-DL/Services/SeqLoggingService.cs b/Cajetan.OF-DL/Services/CajetanLoggingService.cs similarity index 67% rename from Cajetan.OF-DL/Services/SeqLoggingService.cs rename to Cajetan.OF-DL/Services/CajetanLoggingService.cs index 6efcea4..5c26f3b 100644 --- a/Cajetan.OF-DL/Services/SeqLoggingService.cs +++ b/Cajetan.OF-DL/Services/CajetanLoggingService.cs @@ -1,13 +1,11 @@ -using OF_DL.Enumerations; -using Serilog; using Serilog.Core; using Serilog.Events; namespace OF_DL.Services; -public class SeqLoggingService : ILoggingService +public class CajetanLoggingService : ILoggingService { - public SeqLoggingService() + public CajetanLoggingService() { LevelSwitch = new LoggingLevelSwitch(); InitializeLoggerWithSeq(); @@ -35,15 +33,21 @@ public class SeqLoggingService : ILoggingService private void InitializeLoggerWithSeq() { - Log.Logger = new LoggerConfiguration() + LevelSwitch.MinimumLevel = LogEventLevel.Warning; + + LoggerConfiguration loggerConfig = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithProperty("Application", "OF_DL") .Enrich.WithProperty("StartTime", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ") .Enrich.WithProperty("MachineName", Environment.MachineName) - .MinimumLevel.ControlledBy(LevelSwitch) - .WriteTo.File("logs/OFDL.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error) - .WriteTo.Seq("https://seq.cajetan.dk") - .CreateLogger(); + .MinimumLevel.Verbose() + .WriteTo.File("logs/OFDL.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error, levelSwitch: LevelSwitch) + .WriteTo.Seq("https://seq.cajetan.dk", controlLevelSwitch: LevelSwitch); + + if (System.Diagnostics.Debugger.IsAttached) + loggerConfig.WriteTo.Debug(restrictedToMinimumLevel: LogEventLevel.Debug); + + Log.Logger = loggerConfig.CreateLogger(); Log.Debug("Logging service initialized"); }