From 6283f6e6953a9083617bf10180abdf66f66d202a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 16 Apr 2025 09:17:47 -0500 Subject: [PATCH] Moar --- Program.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Program.cs b/Program.cs index 7b3cfb5..538bafb 100644 --- a/Program.cs +++ b/Program.cs @@ -17,7 +17,11 @@ await RunMqttServer(args); async Task RunMqttServer(string[] args) { - ConfigureLogging(); + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .WriteTo.Console(new RenderedCompactJsonFormatter()) + // .WriteTo.File(new RenderedCompactJsonFormatter(), "log.json", rollingInterval: RollingInterval.Hour) + .CreateLogger(); // Create and configure MQTT server using var mqttServer = new MqttServerFactory() @@ -36,15 +40,6 @@ async Task RunMqttServer(string[] args) await SetupGracefulShutdown(mqttServer, lifetime, host); } -void ConfigureLogging() -{ - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .WriteTo.Console(new RenderedCompactJsonFormatter()) - // .WriteTo.File(new RenderedCompactJsonFormatter(), "log.json", rollingInterval: RollingInterval.Hour) - .CreateLogger(); -} - MqttServerOptions BuildMqttServerOptions() { var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; @@ -127,13 +122,14 @@ async Task HandleInterceptingPublish(InterceptingPublishEventArgs args) Task HandleInterceptingSubscription(InterceptingSubscriptionEventArgs args) { - args.ProcessSubscription = true; // Add filtering logic here if needed + // Add filtering logic here if needed + args.ProcessSubscription = true; return Task.CompletedTask; } Task HandleValidatingConnection(ValidatingConnectionEventArgs args) { - // Add authentication logic here + // Add connection / authentication logic here if needed args.ReasonCode = MqttConnectReasonCode.Success; return Task.CompletedTask; } @@ -196,7 +192,7 @@ async Task SetupGracefulShutdown(MqttServer mqttServer, IHostApplicationLifetime ended.Set(); lifetime.StopApplication(); - host.WaitForShutdownAsync().Wait(); + await host.WaitForShutdownAsync(); } static IHostBuilder CreateHostBuilder(string[] args)