From f52fa562d33a5e97f3538734e17044227da4c0de Mon Sep 17 00:00:00 2001 From: Christophe Savard Date: Sun, 10 Aug 2025 01:17:18 -0400 Subject: [PATCH 1/2] Add back symbols --- ImageStitcher/ImageStitcher.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/ImageStitcher/ImageStitcher.csproj b/ImageStitcher/ImageStitcher.csproj index 245782f..619e4a7 100644 --- a/ImageStitcher/ImageStitcher.csproj +++ b/ImageStitcher/ImageStitcher.csproj @@ -25,7 +25,6 @@ - none bin\Release\ImageStitcher.xml From 75361b05ad020d9e2edc7542bbc0a2407882af74 Mon Sep 17 00:00:00 2001 From: Christophe Savard Date: Sun, 17 Aug 2025 02:06:17 -0400 Subject: [PATCH 2/2] Switch to serilog for logging --- ImageStitcher/ImageStitcher.csproj | 3 ++- ImageStitcher/Program.cs | 42 ++++++++++++++---------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/ImageStitcher/ImageStitcher.csproj b/ImageStitcher/ImageStitcher.csproj index 619e4a7..03ab90a 100644 --- a/ImageStitcher/ImageStitcher.csproj +++ b/ImageStitcher/ImageStitcher.csproj @@ -34,7 +34,8 @@ - + + diff --git a/ImageStitcher/Program.cs b/ImageStitcher/Program.cs index f3db685..9284bf7 100644 --- a/ImageStitcher/Program.cs +++ b/ImageStitcher/Program.cs @@ -1,44 +1,40 @@ using DotMake.CommandLine; using ImageStitcher; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; +using Serilog; // DI Configuration Cli.Ext.ConfigureServices(services => { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .Enrich.FromLogContext() + .CreateLogger(); + services.AddLogging(builder => { - builder.AddSimpleConsole(options => - { - options.SingleLine = true; - options.IncludeScopes = true; - options.UseUtcTimestamp = false; - options.TimestampFormat = "HH:mm:ss "; - }); + builder.AddSerilog(Log.Logger, true); }); services.AddSingleton(); }); -int result; if (args is []) { - // If no args, print help - result = await Cli.RunAsync("-h").ConfigureAwait(false); + args = ["-h"]; +} + +int result; +try +{ + // Try running the command + result = await Cli.RunAsync(args).ConfigureAwait(false); } -else +catch (Exception e) { - try - { - // Try running the command - result = await Cli.RunAsync(args).ConfigureAwait(false); - } - catch (Exception e) - { - // Log exceptions - await Console.Error.WriteLineAsync($"[{e.GetType().Name}]: {e.Message}\n{e.StackTrace}").ConfigureAwait(false); - result = 1; - } + // Log exceptions + Log.Error(e, "An error occured while executing the command."); + result = 1; } return result;