From 8108b9dfdb167317f187056a1d0351308e743b00 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 18 Feb 2025 11:59:26 -0600 Subject: [PATCH] fix: attempt to get better logging for exception Fixed some issues with log messages that were not formatted correctly for Serilog. --- .../Routing/Extensions.cs | 29 +++++++++++-------- .../Routing/RouteDescriptorCollection.cs | 8 ++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/Extensions.cs b/src/PepperDash.Essentials.Core/Routing/Extensions.cs index 1956ed27..f7b235ae 100644 --- a/src/PepperDash.Essentials.Core/Routing/Extensions.cs +++ b/src/PepperDash.Essentials.Core/Routing/Extensions.cs @@ -141,23 +141,28 @@ namespace PepperDash.Essentials.Core /// public static void ReleaseRoute(this IRoutingInputs destination, string inputPortKey) { - - Debug.LogMessage(LogEventLevel.Information, "Release route for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); - - if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling) + try { - var coolingDevice = destination as IWarmingCooling; + Debug.LogMessage(LogEventLevel.Information, "Release route for '{destination}':'{inputPortKey}'", destination?.Key ?? "", string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); - coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRequest.HandleCooldown; - } + if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling) + { + var coolingDevice = destination as IWarmingCooling; - RouteRequests.Remove(destination.Key); + coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRequest.HandleCooldown; + } - var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination, inputPortKey); - if (current != null) + RouteRequests.Remove(destination.Key); + + var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination, inputPortKey); + if (current != null) + { + Debug.LogMessage(LogEventLevel.Information, "Releasing current route: {0}", destination, current.Source.Key); + current.ReleaseRoutes(); + } + } catch (Exception ex) { - Debug.LogMessage(LogEventLevel.Debug, "Releasing current route: {0}", destination, current.Source.Key); - current.ReleaseRoutes(); + Debug.LogMessage(ex, "Exception releasing route for '{destination}':'{inputPortKey}'",null, destination?.Key ?? "", string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); } } diff --git a/src/PepperDash.Essentials.Core/Routing/RouteDescriptorCollection.cs b/src/PepperDash.Essentials.Core/Routing/RouteDescriptorCollection.cs index 6c4a5df5..d058872e 100644 --- a/src/PepperDash.Essentials.Core/Routing/RouteDescriptorCollection.cs +++ b/src/PepperDash.Essentials.Core/Routing/RouteDescriptorCollection.cs @@ -53,14 +53,14 @@ namespace PepperDash.Essentials.Core /// null if no RouteDescriptor for a destination exists public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination) { - Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor", destination); + Debug.LogMessage(LogEventLevel.Information, "Getting route descriptor for '{destination}'", destination?.Key ?? ""); return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination); } public RouteDescriptor GetRouteDescriptorForDestinationAndInputPort(IRoutingInputs destination, string inputPortKey) { - Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); + Debug.LogMessage(LogEventLevel.Information, "Getting route descriptor for '{destination}':'{inputPortKey}'", destination?.Key ?? "", string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination && rd.InputPort != null && rd.InputPort.Key == inputPortKey); } @@ -70,7 +70,7 @@ namespace PepperDash.Essentials.Core /// public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination, string inputPortKey = "") { - Debug.LogMessage(LogEventLevel.Debug, "Removing route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); + Debug.LogMessage(LogEventLevel.Information, "Removing route descriptor for '{destination}':'{inputPortKey}'", destination.Key ?? "", string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); var descr = string.IsNullOrEmpty(inputPortKey) ? GetRouteDescriptorForDestination(destination) @@ -78,7 +78,7 @@ namespace PepperDash.Essentials.Core if (descr != null) RouteDescriptors.Remove(descr); - Debug.LogMessage(LogEventLevel.Debug, "Found route descriptor {routeDescriptor}", destination, descr); + Debug.LogMessage(LogEventLevel.Information, "Found route descriptor {routeDescriptor}", destination, descr); return descr; }