From 1d155fefe765116072bb0de3025130c37762993c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Tue, 5 Mar 2013 13:11:25 -0500 Subject: [PATCH] fixed duplicate logs --- .../Logging/NlogManager.cs | 2 +- .../Logging/LogWindow.xaml.cs | 13 +++++----- .../MainWindow.xaml.cs | 25 +++++++++++++------ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index c5296dcfb2..ec93fbd8eb 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Common.Implementations.Logging /// /// The target. /// The level. - private void AddLogTarget(Target target, LogSeverity level) + public void AddLogTarget(Target target, LogSeverity level) { var config = LogManager.Configuration; config.AddTarget(target.Name, target); diff --git a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs index 226cd8e87b..31739577f1 100644 --- a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs +++ b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs @@ -42,13 +42,14 @@ namespace MediaBrowser.ServerApplication.Logging /// The instance containing the event data. void LogWindow_Loaded(object sender, RoutedEventArgs e) { - var target = new TraceTarget - { - Layout = "${longdate}, ${level}, ${logger}, ${message}" - }; - ((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget"); - AddLogTarget(target, "LogWindowTraceTarget"); + + ((NlogManager)_logManager).AddLogTarget(new TraceTarget + { + Layout = "${longdate}, ${level}, ${logger}, ${message}", + Name = "LogWindowTraceTarget" + + }, LogSeverity.Debug); } /// diff --git a/MediaBrowser.ServerApplication/MainWindow.xaml.cs b/MediaBrowser.ServerApplication/MainWindow.xaml.cs index 8306ec541a..80f959b8bf 100644 --- a/MediaBrowser.ServerApplication/MainWindow.xaml.cs +++ b/MediaBrowser.ServerApplication/MainWindow.xaml.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.ServerApplication { DataContext = this; - Instance_ConfigurationUpdated(null, EventArgs.Empty); + UpdateButtons(); _logManager.LoggerLoaded += LoadLogWindow; _configurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated; @@ -92,6 +92,21 @@ namespace MediaBrowser.ServerApplication /// The source of the event. /// The instance containing the event data. void Instance_ConfigurationUpdated(object sender, EventArgs e) + { + UpdateButtons(); + + Dispatcher.InvokeAsync(() => + { + var logWindow = App.Instance.Windows.OfType().FirstOrDefault(); + + if ((logWindow == null && _configurationManager.Configuration.ShowLogWindow) || (logWindow != null && !_configurationManager.Configuration.ShowLogWindow)) + { + _logManager.ReloadLogger(_configurationManager.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); + } + }); + } + + private void UpdateButtons() { Dispatcher.InvokeAsync(() => { @@ -102,13 +117,6 @@ namespace MediaBrowser.ServerApplication separatorDeveloperTools.Visibility = developerToolsVisibility; cmdReloadServer.Visibility = developerToolsVisibility; cmOpenExplorer.Visibility = developerToolsVisibility; - - var logWindow = App.Instance.Windows.OfType().FirstOrDefault(); - - if ((logWindow == null && _configurationManager.Configuration.ShowLogWindow) || (logWindow != null && !_configurationManager.Configuration.ShowLogWindow)) - { - _logManager.ReloadLogger(_configurationManager.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); - } }); } @@ -120,6 +128,7 @@ namespace MediaBrowser.ServerApplication void LoadLogWindow(object sender, EventArgs args) { CloseLogWindow(); + Dispatcher.InvokeAsync(() => { // Add our log window if specified