diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
index 1e525137cf..c5296dcfb2 100644
--- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
+++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Model.Logging;
+using System.Linq;
+using MediaBrowser.Model.Logging;
using NLog;
using NLog.Config;
using NLog.Targets;
@@ -56,23 +57,21 @@ namespace MediaBrowser.Common.Implementations.Logging
logFile.FileName = path;
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}";
- AddLogTarget(logFile, "ApplicationLogFile", level);
+ RemoveTarget("ApplicationLogFile");
+ logFile.Name = "ApplicationLogFile";
+
+ AddLogTarget(logFile, level);
}
///
/// Adds the log target.
///
/// The target.
- /// The name.
/// The level.
- private void AddLogTarget(Target target, string name, LogSeverity level)
+ private void AddLogTarget(Target target, LogSeverity level)
{
var config = LogManager.Configuration;
-
- config.RemoveTarget(name);
-
- target.Name = name;
- config.AddTarget(name, target);
+ config.AddTarget(target.Name, target);
var rule = new LoggingRule("*", GetLogLevel(level), target);
config.LoggingRules.Add(rule);
@@ -80,6 +79,35 @@ namespace MediaBrowser.Common.Implementations.Logging
LogManager.Configuration = config;
}
+ ///
+ /// Removes the target.
+ ///
+ /// The name.
+ public void RemoveTarget(string name)
+ {
+ var config = LogManager.Configuration;
+
+ var target = config.FindTargetByName(name);
+
+ if (target != null)
+ {
+ foreach (var rule in config.LoggingRules.ToList())
+ {
+ var contains = rule.Targets.Contains(target);
+
+ rule.Targets.Remove(target);
+
+ if (contains)
+ {
+ config.LoggingRules.Remove(rule);
+ }
+ }
+
+ config.RemoveTarget(name);
+ LogManager.Configuration = config;
+ }
+ }
+
///
/// Gets the logger.
///
diff --git a/MediaBrowser.Common/Kernel/ResourcePool.cs b/MediaBrowser.Common/Kernel/ResourcePool.cs
deleted file mode 100644
index 7a74c60a78..0000000000
--- a/MediaBrowser.Common/Kernel/ResourcePool.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using System;
-using System.Threading;
-
-namespace MediaBrowser.Common.Kernel
-{
- ///
- /// This is just a collection of semaphores to control the number of concurrent executions of various resources
- ///
- public class ResourcePool : IDisposable
- {
- ///
- /// You tube
- ///
- public readonly SemaphoreSlim YouTube = new SemaphoreSlim(5, 5);
-
- ///
- /// The trakt
- ///
- public readonly SemaphoreSlim Trakt = new SemaphoreSlim(5, 5);
-
- ///
- /// The tv db
- ///
- public readonly SemaphoreSlim TvDb = new SemaphoreSlim(5, 5);
-
- ///
- /// The movie db
- ///
- public readonly SemaphoreSlim MovieDb = new SemaphoreSlim(5, 5);
-
- ///
- /// The fan art
- ///
- public readonly SemaphoreSlim FanArt = new SemaphoreSlim(5, 5);
-
- ///
- /// The mb
- ///
- public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5);
-
- ///
- /// The mb
- ///
- public readonly SemaphoreSlim Lastfm = new SemaphoreSlim(5, 5);
-
- ///
- /// Apple doesn't seem to like too many simulataneous requests.
- ///
- public readonly SemaphoreSlim AppleTrailerVideos = new SemaphoreSlim(1, 1);
-
- ///
- /// The apple trailer images
- ///
- public readonly SemaphoreSlim AppleTrailerImages = new SemaphoreSlim(1, 1);
-
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// Releases unmanaged and - optionally - managed resources.
- ///
- /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
- protected virtual void Dispose(bool dispose)
- {
- if (dispose)
- {
- YouTube.Dispose();
- Trakt.Dispose();
- TvDb.Dispose();
- MovieDb.Dispose();
- FanArt.Dispose();
- Mb.Dispose();
- AppleTrailerVideos.Dispose();
- AppleTrailerImages.Dispose();
- }
- }
- }
-}
diff --git a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs
index 75ef69924b..226cd8e87b 100644
--- a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs
+++ b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs
@@ -1,4 +1,6 @@
-using NLog;
+using MediaBrowser.Common.Implementations.Logging;
+using MediaBrowser.Model.Logging;
+using NLog;
using NLog.Config;
using NLog.Targets;
using System.ComponentModel;
@@ -18,14 +20,17 @@ namespace MediaBrowser.ServerApplication.Logging
///
private readonly TaskScheduler _uiThread;
+ private readonly ILogManager _logManager;
+
///
/// Initializes a new instance of the class.
///
/// The kernel.
- public LogWindow()
+ public LogWindow(ILogManager logManager)
{
InitializeComponent();
_uiThread = TaskScheduler.FromCurrentSynchronizationContext();
+ _logManager = logManager;
Loaded += LogWindow_Loaded;
}
@@ -42,6 +47,7 @@ namespace MediaBrowser.ServerApplication.Logging
Layout = "${longdate}, ${level}, ${logger}, ${message}"
};
+ ((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
AddLogTarget(target, "LogWindowTraceTarget");
}
@@ -53,7 +59,7 @@ namespace MediaBrowser.ServerApplication.Logging
{
base.OnClosing(e);
- RemoveLogTarget("LogWindowTraceTarget");
+ ((NlogManager) _logManager).RemoveTarget("LogWindowTraceTarget");
}
///
@@ -83,8 +89,6 @@ namespace MediaBrowser.ServerApplication.Logging
{
var config = NLog.LogManager.Configuration;
- config.RemoveTarget(name);
-
target.Name = name;
config.AddTarget(name, target);
@@ -95,19 +99,6 @@ namespace MediaBrowser.ServerApplication.Logging
NLog.LogManager.Configuration = config;
}
-
- ///
- /// Removes the log target.
- ///
- /// The name.
- private void RemoveLogTarget(string name)
- {
- var config = NLog.LogManager.Configuration;
-
- config.RemoveTarget(name);
-
- NLog.LogManager.Configuration = config;
- }
///
/// Shuts down.
diff --git a/MediaBrowser.ServerApplication/MainWindow.xaml.cs b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
index 9043e007f2..22695602c5 100644
--- a/MediaBrowser.ServerApplication/MainWindow.xaml.cs
+++ b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
@@ -125,7 +125,7 @@ namespace MediaBrowser.ServerApplication
// Add our log window if specified
if (_configurationManager.Configuration.ShowLogWindow)
{
- Trace.Listeners.Add(new WindowTraceListener(new LogWindow()));
+ Trace.Listeners.Add(new WindowTraceListener(new LogWindow(_logManager)));
}
else
{