Integrate GitVersion and add version provider abstraction
- Added GitVersion for semantic versioning and build metadata - Introduced IVersionProvider and VersionProvider for UI-friendly version display - MainForm now uses IVersionProvider for version label - Registered VersionProvider in DI container - Improved logging: filtered out AutoMapper license logs - General code cleanup in Program.cs
This commit is contained in:
parent
5cb491f1b5
commit
509d5357a8
8 changed files with 154 additions and 44 deletions
|
|
@ -15,7 +15,7 @@ static class Program
|
|||
{
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool AllocConsole();
|
||||
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ static class Program
|
|||
Console.SetOut(standardOutput);
|
||||
Console.SetError(standardOutput);
|
||||
}
|
||||
|
||||
|
||||
public static IServiceProvider ServiceProvider { get; private set; }
|
||||
[STAThread]
|
||||
static void Main()
|
||||
|
|
@ -64,7 +64,7 @@ static class Program
|
|||
|
||||
AllocConsole();
|
||||
RedirectConsoleOutput();
|
||||
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
ConfigureServices(serviceCollection);
|
||||
|
||||
|
|
@ -97,10 +97,13 @@ static class Program
|
|||
"ImageCatalog", "userprefs.xml");
|
||||
services.AddSingleton(new ParametriSetup(userPrefsPath));
|
||||
services.AddSingleton<PicSettings>();
|
||||
|
||||
|
||||
// Register your forms
|
||||
services.AddTransient<MainForm>();
|
||||
|
||||
// Version provider for UI and logging
|
||||
services.AddSingleton<MaddoShared.IVersionProvider, MaddoShared.VersionProvider>();
|
||||
|
||||
services.AddLogging(configure =>
|
||||
{
|
||||
configure.AddCustomFormatter();
|
||||
|
|
@ -110,40 +113,42 @@ static class Program
|
|||
}
|
||||
}
|
||||
|
||||
public static class ConsoleLoggerExtensions
|
||||
{
|
||||
public static ILoggingBuilder AddCustomFormatter(
|
||||
this ILoggingBuilder builder) =>
|
||||
builder.AddConsole(options => options.FormatterName = nameof(CustomLoggingFormatter))
|
||||
.AddConsoleFormatter<CustomLoggingFormatter, ConsoleFormatterOptions>();
|
||||
}
|
||||
public sealed class CustomLoggingFormatter : ConsoleFormatter, IDisposable
|
||||
{
|
||||
private readonly IDisposable _optionsReloadToken;
|
||||
private ConsoleFormatterOptions _formatterOptions;
|
||||
public CustomLoggingFormatter(IOptionsMonitor<ConsoleFormatterOptions> options)
|
||||
public static class ConsoleLoggerExtensions
|
||||
{
|
||||
public static ILoggingBuilder AddCustomFormatter(
|
||||
this ILoggingBuilder builder) =>
|
||||
builder
|
||||
.AddConsole(options => options.FormatterName = nameof(CustomLoggingFormatter))
|
||||
.AddConsoleFormatter<CustomLoggingFormatter, ConsoleFormatterOptions>()
|
||||
.AddFilter("LuckyPennySoftware.AutoMapper.License", LogLevel.None);
|
||||
}
|
||||
public sealed class CustomLoggingFormatter : ConsoleFormatter, IDisposable
|
||||
{
|
||||
private readonly IDisposable _optionsReloadToken;
|
||||
private ConsoleFormatterOptions _formatterOptions;
|
||||
public CustomLoggingFormatter(IOptionsMonitor<ConsoleFormatterOptions> options)
|
||||
// Case insensitive
|
||||
: base(nameof(CustomLoggingFormatter)) =>
|
||||
(_optionsReloadToken, _formatterOptions) =
|
||||
(options.OnChange(ReloadLoggerOptions), options.CurrentValue);
|
||||
private void ReloadLoggerOptions(ConsoleFormatterOptions options) =>
|
||||
_formatterOptions = options;
|
||||
|
||||
public override void Write<TState>(
|
||||
in LogEntry<TState> logEntry,
|
||||
IExternalScopeProvider scopeProvider,
|
||||
TextWriter textWriter)
|
||||
{
|
||||
string? message =
|
||||
logEntry.Formatter?.Invoke(
|
||||
logEntry.State, logEntry.Exception);
|
||||
|
||||
if (message is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textWriter.WriteLine($"{message}");
|
||||
}
|
||||
public void Dispose() => _optionsReloadToken?.Dispose();
|
||||
}
|
||||
: base(nameof(CustomLoggingFormatter)) =>
|
||||
(_optionsReloadToken, _formatterOptions) =
|
||||
(options.OnChange(ReloadLoggerOptions), options.CurrentValue);
|
||||
private void ReloadLoggerOptions(ConsoleFormatterOptions options) =>
|
||||
_formatterOptions = options;
|
||||
|
||||
public override void Write<TState>(
|
||||
in LogEntry<TState> logEntry,
|
||||
IExternalScopeProvider scopeProvider,
|
||||
TextWriter textWriter)
|
||||
{
|
||||
string? message =
|
||||
logEntry.Formatter?.Invoke(
|
||||
logEntry.State, logEntry.Exception);
|
||||
|
||||
if (message is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textWriter.WriteLine($"{message}");
|
||||
}
|
||||
public void Dispose() => _optionsReloadToken?.Dispose();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue