diff --git a/ImageStitcher/ImageStitcher.csproj b/ImageStitcher/ImageStitcher.csproj index 245782f..03ab90a 100644 --- a/ImageStitcher/ImageStitcher.csproj +++ b/ImageStitcher/ImageStitcher.csproj @@ -25,7 +25,6 @@ - none bin\Release\ImageStitcher.xml @@ -35,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;