fixed multiple log files

This commit is contained in:
LukePulverenti
2013-03-04 11:31:33 -05:00
parent 1847a4bdb3
commit 16b36d4d89
4 changed files with 47 additions and 112 deletions

View File

@@ -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.

View File

@@ -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
{