This commit is contained in:
Ben Meadors
2025-04-16 09:17:47 -05:00
parent 84fcd568a1
commit 6283f6e695

View File

@@ -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)