From e6f4ebe4cb9983161f6087e622849bf1cd8aefc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 11 Sep 2023 22:42:52 +0200 Subject: [PATCH] adds basic serilog setup --- .../PiwigoDirectorySync.csproj | 7 ++++-- PiwigoDirectorySync/Program.cs | 24 +++++++++++++------ .../Properties/launchSettings.json | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/PiwigoDirectorySync/PiwigoDirectorySync.csproj b/PiwigoDirectorySync/PiwigoDirectorySync.csproj index abe269a..517c545 100644 --- a/PiwigoDirectorySync/PiwigoDirectorySync.csproj +++ b/PiwigoDirectorySync/PiwigoDirectorySync.csproj @@ -23,9 +23,12 @@ - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/PiwigoDirectorySync/Program.cs b/PiwigoDirectorySync/Program.cs index 9f8f021..6d6dfe8 100644 --- a/PiwigoDirectorySync/Program.cs +++ b/PiwigoDirectorySync/Program.cs @@ -6,18 +6,28 @@ using PiwigoDirectorySync.Commands; using PiwigoDirectorySync.Infrastructure; using PiwigoDirectorySync.Persistence; using PiwigoDirectorySync.Services; +using Serilog; +using Serilog.Events; +using Serilog.Sinks.SystemConsole.Themes; using Spectre.Console.Cli; +const string outputTemplateConsole = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}: {Message}"; +const string outputTemplateFile = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{NewLine}{Exception}{NewLine}"; + +Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("System", LogEventLevel.Warning) + .MinimumLevel.Override("Piwigo.Client", LogEventLevel.Warning) + .Enrich.FromLogContext() + .WriteTo.Console(LogEventLevel.Warning, outputTemplateConsole, theme: AnsiConsoleTheme.Literate) + .WriteTo.File("logs/PiwigoDirectorySync.txt", LogEventLevel.Debug, outputTemplate:outputTemplateFile, rollingInterval: RollingInterval.Day) + .CreateLogger(); + var registrations = new ServiceCollection(); registrations.AddSingleton(AppSettings.Config); -registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging")) - .AddSimpleConsole(c => - { - c.SingleLine = true; - c.IncludeScopes = true; - }) - .AddDebug()); +registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging")).AddSerilog()); registrations.AddTransient(); registrations.AddTransient(); diff --git a/PiwigoDirectorySync/Properties/launchSettings.json b/PiwigoDirectorySync/Properties/launchSettings.json index 0fdf7cb..0e6594e 100644 --- a/PiwigoDirectorySync/Properties/launchSettings.json +++ b/PiwigoDirectorySync/Properties/launchSettings.json @@ -3,7 +3,7 @@ "profiles": { "ScanLocalJpgs": { "commandName": "Project", - "commandLineArgs": "scan 2", + "commandLineArgs": "scan 1", "environmentVariables": { } },