From 993725b4d82ccc98e860d8a4dee49df45865207e Mon Sep 17 00:00:00 2001 From: easly1989 Date: Mon, 11 Nov 2019 12:45:03 +0100 Subject: [PATCH] Added settings to handle logging customization - At first start logging is always Debug, only after that the user settings will be read and override the default. - Logging levels: Debug > Fatal > Error > Warn > Info - this means that selecting Debug will show also every other logged message, while selecting info will show only the green messages --- DFAssist/DFAssistPlugin.cs | 10 +++++++- DFAssist/Helpers/ACTPluginSettingsHelper.cs | 4 ++- .../Helpers/DFAssistRepositoriesHelper.cs | 1 + .../Helpers/DFAssistUIInteractionHelper.cs | 25 ++++++++++++++++--- DFAssist/MainControl.cs | 23 +++++++++++++++++ DFAssist/Resources/localization/de-de.json | 2 ++ DFAssist/Resources/localization/en-us.json | 2 ++ DFAssist/Resources/localization/fr-fr.json | 2 ++ DFAssist/Resources/localization/ja-jp.json | 2 ++ DFAssist/Resources/localization/ko-kr.json | 2 ++ 10 files changed, 67 insertions(+), 6 deletions(-) diff --git a/DFAssist/DFAssistPlugin.cs b/DFAssist/DFAssistPlugin.cs index 7b7cd94..44d7821 100644 --- a/DFAssist/DFAssistPlugin.cs +++ b/DFAssist/DFAssistPlugin.cs @@ -89,7 +89,15 @@ public void InitPlugin(MainControl mainControl) _mainControl.LanguageComboBox.ValueMember = "Code"; _mainControl.TtsVoicesComboBox.DataSource = TTSHelper.Instance.AvailableVoices.Select(x => x.VoiceInfo.Name).ToArray(); - + _mainControl.LogLevelComboBox.DataSource = new [] + { + "Debug", + "Info", + "Warn", + "Error", + "Fatal", + }; + _pluginData.tpPluginSpace.Controls.Add(_mainControl); ACTPluginSettingsHelper.Instance.LoadSettings(); diff --git a/DFAssist/Helpers/ACTPluginSettingsHelper.cs b/DFAssist/Helpers/ACTPluginSettingsHelper.cs index 363d1d7..52a363f 100644 --- a/DFAssist/Helpers/ACTPluginSettingsHelper.cs +++ b/DFAssist/Helpers/ACTPluginSettingsHelper.cs @@ -42,6 +42,7 @@ public void LoadSettings() _xmlSettingsSerializer.AddControlSetting(_mainControl.TtsVoicesComboBox.Name, _mainControl.TtsVoicesComboBox); _xmlSettingsSerializer.AddControlSetting(_mainControl.PersistToasts.Name, _mainControl.PersistToasts); _xmlSettingsSerializer.AddControlSetting(_mainControl.EnableTestEnvironment.Name, _mainControl.EnableTestEnvironment); + _xmlSettingsSerializer.AddControlSetting(_mainControl.LogLevelComboBox.Name, _mainControl.LogLevelComboBox); _xmlSettingsSerializer.AddControlSetting(_mainControl.EnableActToast.Name, _mainControl.EnableActToast); _xmlSettingsSerializer.AddControlSetting(_mainControl.TelegramCheckBox.Name, _mainControl.TelegramCheckBox); _xmlSettingsSerializer.AddControlSetting(_mainControl.TelegramTokenTextBox.Name, _mainControl.TelegramTokenTextBox); @@ -104,7 +105,6 @@ public void LoadSettings() { _logger.Write($"Selected TTS Voice: {_mainControl.TtsVoicesComboBox.SelectedValue}", LogLevel.Debug); } - _logger.Write($"Enable Test Environment: {_mainControl.EnableTestEnvironment.Checked}", LogLevel.Debug); _logger.Write($"Enable Discord Notifications: {_mainControl.DiscordCheckBox.Checked}", LogLevel.Debug); if(_mainControl.DiscordCheckBox.Checked) { @@ -123,6 +123,8 @@ public void LoadSettings() _logger.Write($"Pushbullet Token: {_mainControl.PushBulletTokenTextBox.Text}", LogLevel.Debug); _logger.Write($"Pushbullet ChatId: {_mainControl.PushBulletDeviceIdTextBox.Text}", LogLevel.Debug); } + _logger.Write($"Enable Test Environment: {_mainControl.EnableTestEnvironment.Checked}", LogLevel.Debug); + _logger.Write($"Log Level Selected: {_mainControl.LogLevelComboBox.SelectedValue}", LogLevel.Debug); _logger.Write("Settings Loaded!", LogLevel.Debug); } diff --git a/DFAssist/Helpers/DFAssistRepositoriesHelper.cs b/DFAssist/Helpers/DFAssistRepositoriesHelper.cs index 425e7e6..53c4012 100644 --- a/DFAssist/Helpers/DFAssistRepositoriesHelper.cs +++ b/DFAssist/Helpers/DFAssistRepositoriesHelper.cs @@ -93,6 +93,7 @@ private void UpdateTranslations() _mainControl.DiscordUsernameLabel.Text = _localizationRepository.GetText("ui-discord-username-display-text"); _mainControl.DiscordWebhookLabel.Text = _localizationRepository.GetText("ui-discord-webhook-display-text"); _mainControl.TestSettings.Text = _localizationRepository.GetText("ui-test-settings-group"); + _mainControl.LogLevelSelectionLabel.Text = _localizationRepository.GetText("ui-test-log-level-selction-label"); _logger.Write("UI Updated!", LogLevel.Debug); } diff --git a/DFAssist/Helpers/DFAssistUIInteractionHelper.cs b/DFAssist/Helpers/DFAssistUIInteractionHelper.cs index bbef69a..905426a 100644 --- a/DFAssist/Helpers/DFAssistUIInteractionHelper.cs +++ b/DFAssist/Helpers/DFAssistUIInteractionHelper.cs @@ -35,6 +35,10 @@ public DFAssistUIInteractionHelper() _mainControl.PushBulletDeviceIdTextBox.Enabled = _mainControl.PushBulletCheckbox.Checked; _mainControl.DiscordWebhookTextBox.Enabled = _mainControl.DiscordCheckBox.Checked; _mainControl.DiscordUsernameTextBox.Enabled = _mainControl.DiscordCheckBox.Checked; + + // force initialization of combobox values, not related a subvalue (like the language) + LogLevelComboBoxOnSelectedValueChanged(this, new EventArgs()); + TtsVoicesComboBoxOnSelectedValueChanged(this, new EventArgs()); } public void Subscribe() @@ -56,10 +60,9 @@ public void Subscribe() _mainControl.PushBulletCheckbox.CheckStateChanged += EnablePushBulletOnCheckedChanged; _mainControl.ClearLogButton.Click += ClearLogsButton_Click; _mainControl.TestConfigurationButton.Click += TestConfigurationButton_Click; - + _mainControl.LogLevelComboBox.SelectedValueChanged += LogLevelComboBoxOnSelectedValueChanged; } - public void UnSubscribe() { if (!_subscribed) @@ -79,6 +82,20 @@ public void UnSubscribe() _mainControl.PushBulletCheckbox.CheckStateChanged -= EnablePushBulletOnCheckedChanged; _mainControl.ClearLogButton.Click -= ClearLogsButton_Click; _mainControl.TestConfigurationButton.Click -= TestConfigurationButton_Click; + _mainControl.LogLevelComboBox.SelectedValueChanged += LogLevelComboBoxOnSelectedValueChanged; + } + + private void LogLevelComboBoxOnSelectedValueChanged(object sender, EventArgs e) + { + var selectedValue = _mainControl.LogLevelComboBox.SelectedValue as string; + if(string.IsNullOrWhiteSpace(selectedValue) || !Enum.TryParse(selectedValue, out LogLevel logLevel)) + { + _logger.Write($"UI: [LogLevel] Unable to change log level", LogLevel.Error); + return; + } + + _logger.SetLoggingLevel(logLevel); + _logger.Write($"UI: [LogLevel] Desired Value: {_mainControl.LogLevelComboBox.SelectedValue}", LogLevel.Debug); } private void TtsVoicesComboBoxOnSelectedValueChanged(object sender, EventArgs e) @@ -155,14 +172,14 @@ private void PersistToastsOnCheckedChanged(object sender, EventArgs e) return; } - _logger.Write($"UI: [PersistentToasts] Key found in the registry, Removing value!", LogLevel.Debug); + _logger.Write("UI: [PersistentToasts] Key found in the registry, Removing value!", LogLevel.Debug); key.DeleteValue("ShowInActionCenter"); } } } catch (Exception ex) { - _logger.Write(ex, $"UI: Unable to remove/add the registry key to make Toasts persistent!", LogLevel.Error); + _logger.Write(ex, "UI: Unable to remove/add the registry key to make Toasts persistent!", LogLevel.Error); } } diff --git a/DFAssist/MainControl.cs b/DFAssist/MainControl.cs index 175f530..cefb9af 100644 --- a/DFAssist/MainControl.cs +++ b/DFAssist/MainControl.cs @@ -39,6 +39,7 @@ public class MainControl : UserControl public Label PushBulletDeviceIdlabel; public Label PushBulletTokenLabel; public Label TtsVoiceSelectionLabel; + public Label LogLevelSelectionLabel; public TextBox LanguageValue; public TextBox TelegramChatIdTextBox; @@ -60,6 +61,7 @@ public class MainControl : UserControl public ComboBox LanguageComboBox; public ComboBox TtsVoicesComboBox; + public ComboBox LogLevelComboBox; public RichTextBox LoggingRichTextBox; @@ -78,6 +80,8 @@ private void InitializeComponent() LanguageValue = new TextBox(); LanguageComboBox = new ComboBox(); TtsVoicesComboBox = new ComboBox(); + LogLevelSelectionLabel = new Label(); + LogLevelComboBox = new ComboBox(); EnableTestEnvironment = new CheckBox(); TtsVoiceSelectionLabel = new Label(); TtsCheckBox = new CheckBox(); @@ -365,6 +369,23 @@ private void InitializeComponent() EnableTestEnvironment.Text = "Enable Test Environment"; EnableTestEnvironment.UseVisualStyleBackColor = true; // + // _logLevelSelectionLabel + // + LogLevelSelectionLabel.AutoSize = true; + LogLevelSelectionLabel.Location = new Point(3, 45); + LogLevelSelectionLabel.Name = "LogLevelSelectionLabel"; + LogLevelSelectionLabel.TabStop = false; + LogLevelSelectionLabel.Text = "Selected Voice"; + // + // _logLevelComboBox + // + LogLevelComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + LogLevelComboBox.FormattingEnabled = true; + LogLevelComboBox.Location = new Point(90, 45); + LogLevelComboBox.Name = "LogLevelComboBox"; + LogLevelComboBox.Size = new Size(390, 25); + LogLevelComboBox.TabIndex = 18; + // // _appTabControl // _appTabControl.Dock = DockStyle.Fill; @@ -592,6 +613,8 @@ private void InitializeComponent() Dock = DockStyle.Top; TestSettings.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; TestSettings.Controls.Add(EnableTestEnvironment); + TestSettings.Controls.Add(LogLevelSelectionLabel); + TestSettings.Controls.Add(LogLevelComboBox); TestSettings.Name = "TestSettings"; TestSettings.TabStop = false; TestSettings.Text = "Test Settings"; diff --git a/DFAssist/Resources/localization/de-de.json b/DFAssist/Resources/localization/de-de.json index ed00edd..e7e7676 100644 --- a/DFAssist/Resources/localization/de-de.json +++ b/DFAssist/Resources/localization/de-de.json @@ -42,6 +42,8 @@ "ui-disable-toasts": "Toasts deaktivieren", "ui-flash-taskbar": "Flash-Taskleiste, wenn eine Benachrichtigung empfangen wird", + "ui-test-log-level-selction-label": "Protokollstufe", + "ui-general-settings-group": "Allgemeine Einstellungen", "ui-toast-settings-group": "Toast-Einstellungen", "ui-tts-settings-group": "Einstellungen für Text zu Sprache", diff --git a/DFAssist/Resources/localization/en-us.json b/DFAssist/Resources/localization/en-us.json index 45e9dfc..9b8e0be 100644 --- a/DFAssist/Resources/localization/en-us.json +++ b/DFAssist/Resources/localization/en-us.json @@ -41,6 +41,8 @@ "ui-disable-toasts": "Disable Toasts", "ui-flash-taskbar": "Flash Taskbar when a Notification is received", + + "ui-test-log-level-selction-label": "Log Level", "ui-general-settings-group": "General Settings", "ui-toast-settings-group": "Toasts Settings", diff --git a/DFAssist/Resources/localization/fr-fr.json b/DFAssist/Resources/localization/fr-fr.json index 82ef906..1c33ef2 100644 --- a/DFAssist/Resources/localization/fr-fr.json +++ b/DFAssist/Resources/localization/fr-fr.json @@ -42,6 +42,8 @@ "ui-disable-toasts": "Désactiver les notifications", "ui-flash-taskbar": "La barre de tâches clignote quand une notification est reçue", + "ui-test-log-level-selction-label": "Niveau de journalisation", + "ui-general-settings-group": "Paramètres généraux", "ui-toast-settings-group": "Paramètres des notifications", "ui-tts-settings-group": "Paramètres de synthèse vocale", diff --git a/DFAssist/Resources/localization/ja-jp.json b/DFAssist/Resources/localization/ja-jp.json index 48fc204..d9fbfa0 100644 --- a/DFAssist/Resources/localization/ja-jp.json +++ b/DFAssist/Resources/localization/ja-jp.json @@ -42,6 +42,8 @@ "ui-disable-toasts": "トーストを無効にする", "ui-flash-taskbar": "通知を受け取ったときにタスクバーをフラッシュする", + "ui-test-log-level-selction-label": "ログレベル", + "ui-general-settings-group": "一般設定", "ui-toast-settings-group": "トースト設定", "ui-tts-settings-group": "テキスト読み上げ設定", diff --git a/DFAssist/Resources/localization/ko-kr.json b/DFAssist/Resources/localization/ko-kr.json index d9c51d2..9a351d0 100644 --- a/DFAssist/Resources/localization/ko-kr.json +++ b/DFAssist/Resources/localization/ko-kr.json @@ -42,6 +42,8 @@ "ui-disable-toasts": "토스트 비활성화", "ui-flash-taskbar": "알림이 수신되면 Flash 작업 표시 줄", + "ui-test-log-level-selction-label": "로그 레벨", + "ui-general-settings-group": "일반 설정", "ui-toast-settings-group": "토스트 설정", "ui-tts-settings-group": "TTS 설정",