Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ImageStitcher/ImageStitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>none</DebugType>
<DocumentationFile>bin\Release\ImageStitcher.xml</DocumentationFile>
</PropertyGroup>

Expand All @@ -35,7 +34,8 @@
<PackageReference Include="JetBrains.ExternalAnnotations" Version="10.2.163" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 19 additions & 23 deletions ImageStitcher/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Stitcher>();
});

int result;
if (args is [])
{
// If no args, print help
result = await Cli.RunAsync<ImageStitcherCommand>("-h").ConfigureAwait(false);
args = ["-h"];
}

int result;
try
{
// Try running the command
result = await Cli.RunAsync<ImageStitcherCommand>(args).ConfigureAwait(false);
}
else
catch (Exception e)
{
try
{
// Try running the command
result = await Cli.RunAsync<ImageStitcherCommand>(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;