2
0
LukePulverenti 12 жил өмнө
parent
commit
16b36d4d89

+ 37 - 9
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);
         }
 
         /// <summary>
         /// Adds the log target.
         /// </summary>
         /// <param name="target">The target.</param>
-        /// <param name="name">The name.</param>
         /// <param name="level">The level.</param>
-        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;
         }
 
+        /// <summary>
+        /// Removes the target.
+        /// </summary>
+        /// <param name="name">The name.</param>
+        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;
+            }
+        }
+
         /// <summary>
         /// Gets the logger.
         /// </summary>

+ 0 - 84
MediaBrowser.Common/Kernel/ResourcePool.cs

@@ -1,84 +0,0 @@
-using System;
-using System.Threading;
-
-namespace MediaBrowser.Common.Kernel
-{
-    /// <summary>
-    /// This is just a collection of semaphores to control the number of concurrent executions of various resources
-    /// </summary>
-    public class ResourcePool : IDisposable
-    {
-        /// <summary>
-        /// You tube
-        /// </summary>
-        public readonly SemaphoreSlim YouTube = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The trakt
-        /// </summary>
-        public readonly SemaphoreSlim Trakt = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The tv db
-        /// </summary>
-        public readonly SemaphoreSlim TvDb = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The movie db
-        /// </summary>
-        public readonly SemaphoreSlim MovieDb = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The fan art
-        /// </summary>
-        public readonly SemaphoreSlim FanArt = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The mb
-        /// </summary>
-        public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// The mb
-        /// </summary>
-        public readonly SemaphoreSlim Lastfm = new SemaphoreSlim(5, 5);
-
-        /// <summary>
-        /// Apple doesn't seem to like too many simulataneous requests.
-        /// </summary>
-        public readonly SemaphoreSlim AppleTrailerVideos = new SemaphoreSlim(1, 1);
-
-        /// <summary>
-        /// The apple trailer images
-        /// </summary>
-        public readonly SemaphoreSlim AppleTrailerImages = new SemaphoreSlim(1, 1);
-        
-        /// <summary>
-        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
-        /// </summary>
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool dispose)
-        {
-            if (dispose)
-            {
-                YouTube.Dispose();
-                Trakt.Dispose();
-                TvDb.Dispose();
-                MovieDb.Dispose();
-                FanArt.Dispose();
-                Mb.Dispose();
-                AppleTrailerVideos.Dispose();
-                AppleTrailerImages.Dispose();
-            }
-        }
-    }
-}

+ 9 - 18
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
         /// </summary>
         private readonly TaskScheduler _uiThread;
 
+        private readonly ILogManager _logManager;
+
         /// <summary>
         /// Initializes a new instance of the <see cref="LogWindow" /> class.
         /// </summary>
         /// <param name="kernel">The kernel.</param>
-        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");
         }
 
         /// <summary>
@@ -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;
         }
-
-        /// <summary>
-        /// Removes the log target.
-        /// </summary>
-        /// <param name="name">The name.</param>
-        private void RemoveLogTarget(string name)
-        {
-            var config = NLog.LogManager.Configuration;
-
-            config.RemoveTarget(name);
-
-            NLog.LogManager.Configuration = config;
-        }
         
         /// <summary>
         /// Shuts down.

+ 1 - 1
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
                 {