fix: debug all devices when devices array is empty

This commit is contained in:
Nick Genovese
2024-11-07 20:07:26 -05:00
parent 4f01ff1379
commit 1f51c3ef2a
2 changed files with 188 additions and 179 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Serilog;
@@ -56,10 +57,21 @@ namespace PepperDash.Core.Logging
return false;
}
if (@event.Properties.TryGetValue("Key", out var value) &&
value is ScalarValue { Value: string rawValue })
if (@event.Properties.TryGetValue("Key", out var value) && value is ScalarValue { Value: string rawValue }
&& DebugContext.TryGetDataForKey(Debug.ConsoleLevelStoreKey, out var data)
&& data.Devices != null)
{
return DebugContext.DeviceExistsInContext(Debug.ConsoleLevelStoreKey, rawValue);
if (data.Devices.Length == 0)
{
return true;
}
if (data.Devices.Any(d => d == rawValue))
{
return true;
}
return false;
}
return true;

View File

@@ -48,15 +48,12 @@ namespace PepperDash.Core.Logging
};
}
public static DebugContextData GetDataForKey(string key, LogEventLevel defaultLevel) =>
public static bool TryGetDataForKey(string key, out DebugContextData data) =>
CurrentData.TryGetValue(key, out var data);
public static DebugContextData GetOrCreateDataForKey(string key, LogEventLevel defaultLevel) =>
CurrentData.TryGetValue(key, out var data) ? data : new DebugContextData(defaultLevel);
public static bool DeviceExistsInContext(string contextKey, string deviceKey) =>
CurrentData.TryGetValue(contextKey, out var data) switch
{
true when data.Devices != null => data.Devices.Any(key => string.Equals(key, deviceKey, StringComparison.OrdinalIgnoreCase)),
_ => false
};
public static void SetDataForKey(string key, LogEventLevel defaultLevel, string[] devices = null)
{