From 19aefb6ac522216f2f5affa701007efd94366b51 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 11 Jan 2025 12:32:13 +0000 Subject: [PATCH] Add Serilog and configure logger --- .../KeepersCompound.LGS.csproj | 4 ++++ .../KeepersCompound.Lightmapper.csproj | 3 +++ KeepersCompound.Lightmapper/Program.cs | 24 +++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/KeepersCompound.LGS/KeepersCompound.LGS.csproj b/KeepersCompound.LGS/KeepersCompound.LGS.csproj index 412d83d..ba5e203 100644 --- a/KeepersCompound.LGS/KeepersCompound.LGS.csproj +++ b/KeepersCompound.LGS/KeepersCompound.LGS.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/KeepersCompound.Lightmapper/KeepersCompound.Lightmapper.csproj b/KeepersCompound.Lightmapper/KeepersCompound.Lightmapper.csproj index c439fba..592aac2 100644 --- a/KeepersCompound.Lightmapper/KeepersCompound.Lightmapper.csproj +++ b/KeepersCompound.Lightmapper/KeepersCompound.Lightmapper.csproj @@ -14,6 +14,9 @@ + + + diff --git a/KeepersCompound.Lightmapper/Program.cs b/KeepersCompound.Lightmapper/Program.cs index 48b52b8..fd289f6 100644 --- a/KeepersCompound.Lightmapper/Program.cs +++ b/KeepersCompound.Lightmapper/Program.cs @@ -1,11 +1,31 @@ using DotMake.CommandLine; +using Serilog; +using Serilog.Sinks.SystemConsole.Themes; namespace KeepersCompound.Lightmapper; internal static class Program { - public static async Task Main(string[] args) => - await Cli.RunAsync(args); + private static void ConfigureLogger() + { + const string outputTemplate = "{Timestamp:HH:mm:ss.fff} [{Level}] {Message:lj}{NewLine}{Exception}"; + var logPath = $"{AppDomain.CurrentDomain.BaseDirectory}/logs/{DateTime.Now:yyyyMMdd_HHmmss}.log"; + var config = new LoggerConfiguration(); +#if DEBUG + config.MinimumLevel.Debug(); +#endif + + Log.Logger = config + .WriteTo.Console(theme: AnsiConsoleTheme.Sixteen, outputTemplate: outputTemplate) + .WriteTo.File(logPath, outputTemplate: outputTemplate) + .CreateLogger(); + } + + public static async Task Main(string[] args) + { + ConfigureLogger(); + return await Cli.RunAsync(args); + } } [CliCommand(Description = "Compute lightmaps for a NewDark .MIS/.COW")]