2024-08-07 19:41:42 -05:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using LANCommander.Launcher.Services.Extensions;
|
|
|
|
|
|
using LANCommander.Launcher.Services;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using Serilog;
|
2024-09-25 20:33:06 -05:00
|
|
|
|
using Serilog.Core;
|
|
|
|
|
|
using Serilog.Extensions.Logging;
|
2025-06-15 20:01:17 +02:00
|
|
|
|
using Serilog.Events;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
|
|
|
|
|
|
var settings = SettingService.GetSettings();
|
|
|
|
|
|
|
2025-06-15 20:01:17 +02:00
|
|
|
|
// Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel.
|
|
|
|
|
|
var serilogLogLevel = MapLogLevel(settings.Debug.LoggingLevel);
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using var logger = new LoggerConfiguration()
|
2025-06-15 20:01:17 +02:00
|
|
|
|
.MinimumLevel.Is(serilogLogLevel)
|
|
|
|
|
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("Microsoft.AspNetCore.Components", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("AntDesign", LogEventLevel.Warning)
|
2024-09-18 20:40:41 -05:00
|
|
|
|
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
|
|
|
|
|
|
.WriteTo.Console()
|
|
|
|
|
|
.WriteTo.File(Path.Combine(settings.Debug.LoggingPath, "log-.txt"), rollingInterval: settings.Debug.LoggingArchivePeriod)
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
.WriteTo.Seq("http://localhost:5341")
|
|
|
|
|
|
#endif
|
|
|
|
|
|
.CreateLogger();
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
|
|
|
|
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
builder.Services.AddLogging(loggingBuilder =>
|
|
|
|
|
|
{
|
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
|
loggingBuilder.SetMinimumLevel(settings.Debug.LoggingLevel);
|
|
|
|
|
|
loggingBuilder.AddSerilog(logger);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-09-25 20:33:06 -05:00
|
|
|
|
builder.Services.AddLANCommander(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.ServerAddress = settings.Authentication.ServerAddress;
|
|
|
|
|
|
options.Logger = new SerilogLoggerFactory(logger).CreateLogger<LANCommander.SDK.Client>();
|
|
|
|
|
|
});
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
|
|
|
|
|
using IHost host = builder.Build();
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
host.Services.InitializeLANCommander();
|
|
|
|
|
|
|
2024-08-07 19:41:42 -05:00
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
|
|
|
|
|
|
|
|
var commandLineService = scope.ServiceProvider.GetService<CommandLineService>();
|
|
|
|
|
|
|
2025-06-15 20:01:17 +02:00
|
|
|
|
await commandLineService.ParseCommandLineAsync(args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Maps Microsoft.Extensions.Logging.LogLevel to Serilog.Events.LogEventLevel.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
static LogEventLevel MapLogLevel(LogLevel level)
|
|
|
|
|
|
{
|
|
|
|
|
|
return level switch
|
|
|
|
|
|
{
|
|
|
|
|
|
LogLevel.Trace => LogEventLevel.Verbose,
|
|
|
|
|
|
LogLevel.Debug => LogEventLevel.Debug,
|
|
|
|
|
|
LogLevel.Information => LogEventLevel.Information,
|
|
|
|
|
|
LogLevel.Warning => LogEventLevel.Warning,
|
|
|
|
|
|
LogLevel.Error => LogEventLevel.Error,
|
|
|
|
|
|
LogLevel.Critical => LogEventLevel.Fatal,
|
|
|
|
|
|
// LogLevel.None indicates logging should be disabled.
|
|
|
|
|
|
// Serilog does not have a direct "Off" level so you might choose to
|
|
|
|
|
|
// either bypass logging configuration or set it high enough to ignore messages.
|
|
|
|
|
|
LogLevel.None => LogEventLevel.Fatal,
|
|
|
|
|
|
_ => LogEventLevel.Information
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|