fix: add console log level recall

This commit is contained in:
Andrew Welker
2024-03-13 08:21:15 -05:00
parent ada8b7e162
commit 32caa005a3

View File

@@ -21,6 +21,7 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public static class Debug public static class Debug
{ {
private static string LevelStoreKey = "ConsoleDebugLevel";
private static Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>() private static Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
{ {
{0, LogEventLevel.Information }, {0, LogEventLevel.Information },
@@ -101,7 +102,9 @@ namespace PepperDash.Core
static Debug() static Debug()
{ {
_consoleLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Information); var defaultConsoleLevel = GetStoredLogEventLevel();
_consoleLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultConsoleLevel);
_consoleLoggingLevelSwitch.MinimumLevelChanged += (sender, args) => _consoleLoggingLevelSwitch.MinimumLevelChanged += (sender, args) =>
{ {
Console(0, "Console debug level set to {0}", _consoleLoggingLevelSwitch.MinimumLevel); Console(0, "Console debug level set to {0}", _consoleLoggingLevelSwitch.MinimumLevel);
@@ -187,6 +190,24 @@ namespace PepperDash.Core
} }
} }
private static LogEventLevel GetStoredLogEventLevel()
{
try
{
var result = CrestronDataStoreStatic.GetLocalUintValue(LevelStoreKey, out uint logLevel);
if(result != CrestronDataStore.CDS_ERROR.CDS_SUCCESS || logLevel > 5 || logLevel < 0)
{
return LogEventLevel.Information;
}
return _logLevels[logLevel];
} catch
{
return LogEventLevel.Information;
}
}
private static void GetVersion() private static void GetVersion()
{ {
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();