aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Logging
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
commit767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch)
tree49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Common/Logging
parent845554722efaed872948a9e0f7202e3ef52f1b6e (diff)
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Common/Logging')
-rw-r--r--MediaBrowser.Common/Logging/BaseLogger.cs16
-rw-r--r--MediaBrowser.Common/Logging/LogHelper.cs90
-rw-r--r--MediaBrowser.Common/Logging/LogManager.cs20
-rw-r--r--MediaBrowser.Common/Logging/LogRow.cs44
-rw-r--r--MediaBrowser.Common/Logging/LogSeverity.cs14
-rw-r--r--MediaBrowser.Common/Logging/LogWindow.xaml8
-rw-r--r--MediaBrowser.Common/Logging/LogWindow.xaml.cs128
-rw-r--r--MediaBrowser.Common/Logging/Logger.cs203
-rw-r--r--MediaBrowser.Common/Logging/NLogger.cs201
-rw-r--r--MediaBrowser.Common/Logging/TraceFileLogger.cs38
-rw-r--r--MediaBrowser.Common/Logging/WindowTraceListener.cs75
11 files changed, 632 insertions, 205 deletions
diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs
deleted file mode 100644
index a97bc201f2..0000000000
--- a/MediaBrowser.Common/Logging/BaseLogger.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using MediaBrowser.Common.Kernel;
-using System;
-
-namespace MediaBrowser.Common.Logging
-{
- public abstract class BaseLogger : IDisposable
- {
- public abstract void Initialize(IKernel kernel);
- public abstract void LogEntry(LogRow row);
-
- public virtual void Dispose()
- {
- Logger.LogInfo("Disposing " + GetType().Name);
- }
- }
-}
diff --git a/MediaBrowser.Common/Logging/LogHelper.cs b/MediaBrowser.Common/Logging/LogHelper.cs
new file mode 100644
index 0000000000..8b638a28e8
--- /dev/null
+++ b/MediaBrowser.Common/Logging/LogHelper.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Text;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class LogHelper
+ /// </summary>
+ public static class LogHelper
+ {
+ /// <summary>
+ /// Gets the log message.
+ /// </summary>
+ /// <param name="exception">The exception.</param>
+ /// <returns>StringBuilder.</returns>
+ public static StringBuilder GetLogMessage(Exception exception)
+ {
+ var messageText = new StringBuilder();
+
+ messageText.AppendLine(exception.Message);
+
+ messageText.AppendLine(exception.GetType().FullName);
+
+ LogExceptionData(messageText, exception);
+
+ messageText.AppendLine(exception.StackTrace ?? "No Stack Trace Available");
+
+ // Log the InnerExceptions, if any
+ AppendInnerExceptions(messageText, exception);
+
+ messageText.AppendLine(string.Empty);
+
+ return messageText;
+ }
+
+ /// <summary>
+ /// Appends the inner exceptions.
+ /// </summary>
+ /// <param name="messageText">The message text.</param>
+ /// <param name="e">The e.</param>
+ private static void AppendInnerExceptions(StringBuilder messageText, Exception e)
+ {
+ var aggregate = e as AggregateException;
+
+ if (aggregate != null && aggregate.InnerExceptions != null)
+ {
+ foreach (var ex in aggregate.InnerExceptions)
+ {
+ AppendInnerException(messageText, ex);
+ }
+ }
+
+ else if (e.InnerException != null)
+ {
+ AppendInnerException(messageText, e.InnerException);
+ }
+ }
+
+ /// <summary>
+ /// Appends the inner exception.
+ /// </summary>
+ /// <param name="messageText">The message text.</param>
+ /// <param name="e">The e.</param>
+ private static void AppendInnerException(StringBuilder messageText, Exception e)
+ {
+ messageText.AppendLine("InnerException: " + e.GetType().FullName);
+ messageText.AppendLine(e.Message);
+
+ LogExceptionData(messageText, e);
+
+ if (e.StackTrace != null)
+ {
+ messageText.AppendLine(e.StackTrace);
+ }
+ }
+
+ /// <summary>
+ /// Logs the exception data.
+ /// </summary>
+ /// <param name="messageText">The message text.</param>
+ /// <param name="e">The e.</param>
+ private static void LogExceptionData(StringBuilder messageText, Exception e)
+ {
+ foreach (var key in e.Data.Keys)
+ {
+ messageText.AppendLine(key + ": " + e.Data[key]);
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Logging/LogManager.cs b/MediaBrowser.Common/Logging/LogManager.cs
new file mode 100644
index 0000000000..825f04440f
--- /dev/null
+++ b/MediaBrowser.Common/Logging/LogManager.cs
@@ -0,0 +1,20 @@
+using MediaBrowser.Model.Logging;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class LogManager
+ /// </summary>
+ public static class LogManager
+ {
+ /// <summary>
+ /// Gets the logger.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <returns>ILogger.</returns>
+ public static ILogger GetLogger(string name)
+ {
+ return new NLogger(name);
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs
deleted file mode 100644
index 6fecef59cc..0000000000
--- a/MediaBrowser.Common/Logging/LogRow.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace MediaBrowser.Common.Logging
-{
- public struct LogRow
- {
- const string TimePattern = "h:mm:ss.fff tt d/M/yyyy";
-
- public LogSeverity Severity { get; set; }
- public string Message { get; set; }
- public int ThreadId { get; set; }
- public string ThreadName { get; set; }
- public DateTime Time { get; set; }
-
- public override string ToString()
- {
- var data = new List<string>();
-
- data.Add(Time.ToString(TimePattern));
-
- data.Add(Severity.ToString());
-
- if (!string.IsNullOrEmpty(Message))
- {
- data.Add(Encode(Message));
- }
-
- data.Add(ThreadId.ToString());
-
- if (!string.IsNullOrEmpty(ThreadName))
- {
- data.Add(Encode(ThreadName));
- }
-
- return string.Join(" , ", data.ToArray());
- }
-
- private string Encode(string str)
- {
- return (str ?? "").Replace(",", ",,").Replace(Environment.NewLine, " [n] ");
- }
- }
-}
diff --git a/MediaBrowser.Common/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs
deleted file mode 100644
index 97abfe7b58..0000000000
--- a/MediaBrowser.Common/Logging/LogSeverity.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-
-namespace MediaBrowser.Common.Logging
-{
- [Flags]
- public enum LogSeverity
- {
- None = 0,
- Debug = 1,
- Info = 2,
- Warning = 4,
- Error = 8
- }
-} \ No newline at end of file
diff --git a/MediaBrowser.Common/Logging/LogWindow.xaml b/MediaBrowser.Common/Logging/LogWindow.xaml
new file mode 100644
index 0000000000..726d3c968e
--- /dev/null
+++ b/MediaBrowser.Common/Logging/LogWindow.xaml
@@ -0,0 +1,8 @@
+<Window x:Class="MediaBrowser.Common.Logging.LogWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Media Browser Log" Height="300" Width="968">
+ <Grid>
+ <ListBox x:Name="lbxLogData" Margin="10,10,0,0"/>
+ </Grid>
+</Window>
diff --git a/MediaBrowser.Common/Logging/LogWindow.xaml.cs b/MediaBrowser.Common/Logging/LogWindow.xaml.cs
new file mode 100644
index 0000000000..3dc11db5b2
--- /dev/null
+++ b/MediaBrowser.Common/Logging/LogWindow.xaml.cs
@@ -0,0 +1,128 @@
+using MediaBrowser.Common.Kernel;
+using NLog;
+using NLog.Config;
+using NLog.Targets;
+using System.ComponentModel;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Interaction logic for LogWindow.xaml
+ /// </summary>
+ public partial class LogWindow : Window
+ {
+ /// <summary>
+ /// The _ui thread
+ /// </summary>
+ private readonly TaskScheduler _uiThread;
+ /// <summary>
+ /// The _kernel
+ /// </summary>
+ private readonly IKernel _kernel;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LogWindow" /> class.
+ /// </summary>
+ /// <param name="kernel">The kernel.</param>
+ public LogWindow(IKernel kernel)
+ {
+ InitializeComponent();
+ _uiThread = TaskScheduler.FromCurrentSynchronizationContext();
+ _kernel = kernel;
+
+ Loaded += LogWindow_Loaded;
+ }
+
+ /// <summary>
+ /// Handles the Loaded event of the LogWindow control.
+ /// </summary>
+ /// <param name="sender">The source of the event.</param>
+ /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
+ void LogWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+ var target = new TraceTarget
+ {
+ Layout = "${longdate}, ${level}, ${logger}, ${message}"
+ };
+
+ AddLogTarget(target, "LogWindowTraceTarget");
+ }
+
+ /// <summary>
+ /// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
+ /// </summary>
+ /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
+ protected override void OnClosing(CancelEventArgs e)
+ {
+ base.OnClosing(e);
+
+ RemoveLogTarget("LogWindowTraceTarget");
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="msg">The MSG.</param>
+ public async void LogMessage(string msg)
+ {
+ await Task.Factory.StartNew(() => lbxLogData.Items.Insert(0, msg.TrimEnd('\n')), CancellationToken.None, TaskCreationOptions.None, _uiThread);
+ }
+
+ /// <summary>
+ /// The log layout
+ /// </summary>
+ /// <value>The log layout.</value>
+ public string LogLayout
+ {
+ get { return "${longdate}, ${level}, ${logger}, ${message}"; }
+ }
+
+ /// <summary>
+ /// Adds the log target.
+ /// </summary>
+ /// <param name="target">The target.</param>
+ /// <param name="name">The name.</param>
+ private void AddLogTarget(Target target, string name)
+ {
+ var config = NLog.LogManager.Configuration;
+
+ config.RemoveTarget(name);
+
+ target.Name = name;
+ config.AddTarget(name, target);
+
+ var level = _kernel.Configuration.EnableDebugLevelLogging ? LogLevel.Debug : LogLevel.Info;
+
+ var rule = new LoggingRule("*", level, target);
+ config.LoggingRules.Add(rule);
+
+ 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.
+ /// </summary>
+ public async void ShutDown()
+ {
+ await Task.Factory.StartNew(Close, CancellationToken.None, TaskCreationOptions.None, _uiThread);
+ }
+
+ }
+
+}
diff --git a/MediaBrowser.Common/Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs
index 9ac02fe3ea..33d6b7f737 100644
--- a/MediaBrowser.Common/Logging/Logger.cs
+++ b/MediaBrowser.Common/Logging/Logger.cs
@@ -1,93 +1,110 @@
-using System;
-using System.Diagnostics;
-using System.Text;
-using System.Threading;
-using MediaBrowser.Common.Kernel;
-
-namespace MediaBrowser.Common.Logging
-{
- public static class Logger
- {
- internal static IKernel Kernel { get; set; }
-
- public static void LogInfo(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Info, paramList);
- }
-
- public static void LogDebugInfo(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Debug, paramList);
- }
-
- public static void LogError(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Error, paramList);
- }
-
- public static void LogException(Exception ex, params object[] paramList)
- {
- LogException(string.Empty, ex, paramList);
- }
-
- public static void LogException(string message, Exception ex, params object[] paramList)
- {
- var builder = new StringBuilder();
-
- if (ex != null)
- {
- builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}",
- ex.GetType().FullName,
- ex.Message,
- ex.StackTrace,
- Environment.NewLine);
- }
-
- message = FormatMessage(message, paramList);
-
- LogError(string.Format("{0} ( {1} )", message, builder));
- }
-
- public static void LogWarning(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Warning, paramList);
- }
-
- private static void LogEntry(string message, LogSeverity severity, params object[] paramList)
- {
- message = FormatMessage(message, paramList);
-
- Thread currentThread = Thread.CurrentThread;
-
- var row = new LogRow
- {
- Severity = severity,
- Message = message,
- ThreadId = currentThread.ManagedThreadId,
- ThreadName = currentThread.Name,
- Time = DateTime.Now
- };
-
- if (Kernel.Loggers != null)
- {
- foreach (var logger in Kernel.Loggers)
- {
- logger.LogEntry(row);
- }
- }
- }
-
- private static string FormatMessage(string message, params object[] paramList)
- {
- if (paramList != null)
- {
- for (int i = 0; i < paramList.Length; i++)
- {
- message = message.Replace("{" + i + "}", paramList[i].ToString());
- }
- }
-
- return message;
- }
- }
-}
+using MediaBrowser.Model.Logging;
+using System;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class Logger
+ /// </summary>
+ public static class Logger
+ {
+ /// <summary>
+ /// Gets or sets the logger instance.
+ /// </summary>
+ /// <value>The logger instance.</value>
+ internal static ILogger LoggerInstance { get; set; }
+
+ /// <summary>
+ /// Logs the info.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogInfo(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Info, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the debug info.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogDebugInfo(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Debug, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the error.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogError(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Error, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="ex">The ex.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogException(string message, Exception ex, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Error, ex, paramList);
+ }
+
+ /// <summary>
+ /// Fatals the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="ex">The ex.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void FatalException(string message, Exception ex, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Fatal, ex, paramList);
+ }
+
+ /// <summary>
+ /// Logs the warning.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogWarning(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Warn, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the entry.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="paramList">The param list.</param>
+ private static void LogEntry(string message, LogSeverity level, Exception exception, params object[] paramList)
+ {
+ if (LoggerInstance == null)
+ {
+ return;
+ }
+
+ if (exception == null)
+ {
+ LoggerInstance.Log(level, message, paramList);
+ }
+ else
+ {
+ if (level == LogSeverity.Fatal)
+ {
+ LoggerInstance.FatalException(message, exception, paramList);
+ }
+ else
+ {
+ LoggerInstance.ErrorException(message, exception, paramList);
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Logging/NLogger.cs b/MediaBrowser.Common/Logging/NLogger.cs
new file mode 100644
index 0000000000..584c5616bf
--- /dev/null
+++ b/MediaBrowser.Common/Logging/NLogger.cs
@@ -0,0 +1,201 @@
+using MediaBrowser.Model.Logging;
+using System;
+using System.Text;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class NLogger
+ /// </summary>
+ internal class NLogger : ILogger
+ {
+ /// <summary>
+ /// The _logger
+ /// </summary>
+ private readonly NLog.Logger _logger;
+
+ /// <summary>
+ /// The _lock object
+ /// </summary>
+ private static readonly object LockObject = new object();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="NLogger" /> class.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ public NLogger(string name)
+ {
+ lock (LockObject)
+ {
+ _logger = NLog.LogManager.GetLogger(name);
+ }
+ }
+
+ /// <summary>
+ /// Infoes the specified message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Info(string message, params object[] paramList)
+ {
+ _logger.Info(message, paramList);
+ }
+
+ /// <summary>
+ /// Errors the specified message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Error(string message, params object[] paramList)
+ {
+ _logger.Error(message, paramList);
+ }
+
+ /// <summary>
+ /// Warns the specified message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Warn(string message, params object[] paramList)
+ {
+ _logger.Warn(message, paramList);
+ }
+
+ /// <summary>
+ /// Debugs the specified message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Debug(string message, params object[] paramList)
+ {
+ _logger.Debug(message, paramList);
+ }
+
+ /// <summary>
+ /// Logs the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="paramList">The param list.</param>
+ /// <exception cref="System.NotImplementedException"></exception>
+ public void ErrorException(string message, Exception exception, params object[] paramList)
+ {
+ LogException(LogSeverity.Error, message, exception, paramList);
+ }
+
+ /// <summary>
+ /// Logs the exception.
+ /// </summary>
+ /// <param name="level">The level.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="paramList">The param list.</param>
+ private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList)
+ {
+ message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". ");
+
+ var messageText = LogHelper.GetLogMessage(exception);
+
+ LogMultiline(message, level, messageText);
+ }
+
+ /// <summary>
+ /// Formats the message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ /// <returns>System.String.</returns>
+ private static string FormatMessage(string message, params object[] paramList)
+ {
+ if (paramList != null)
+ {
+ for (var i = 0; i < paramList.Length; i++)
+ {
+ message = message.Replace("{" + i + "}", paramList[i].ToString());
+ }
+ }
+
+ return message;
+ }
+
+ /// <summary>
+ /// Logs the multiline.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="severity">The severity.</param>
+ /// <param name="additionalContent">Content of the additional.</param>
+ public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent)
+ {
+ additionalContent.Insert(0, message + Environment.NewLine);
+
+ const char tabChar = '\t';
+
+ var text = additionalContent.ToString()
+ .Replace(Environment.NewLine, Environment.NewLine + tabChar)
+ .TrimEnd(tabChar);
+
+ if (text.EndsWith(Environment.NewLine))
+ {
+ text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase));
+ }
+
+ _logger.Log(GetLogLevel(severity), text);
+ }
+
+ /// <summary>
+ /// Gets the log level.
+ /// </summary>
+ /// <param name="severity">The severity.</param>
+ /// <returns>NLog.LogLevel.</returns>
+ private NLog.LogLevel GetLogLevel(LogSeverity severity)
+ {
+ switch (severity)
+ {
+ case LogSeverity.Debug:
+ return NLog.LogLevel.Debug;
+ case LogSeverity.Error:
+ return NLog.LogLevel.Error;
+ case LogSeverity.Warn:
+ return NLog.LogLevel.Warn;
+ case LogSeverity.Fatal:
+ return NLog.LogLevel.Fatal;
+ case LogSeverity.Info:
+ return NLog.LogLevel.Info;
+ default:
+ throw new ArgumentException("Unknown LogSeverity: " + severity.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Logs the specified severity.
+ /// </summary>
+ /// <param name="severity">The severity.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Log(LogSeverity severity, string message, params object[] paramList)
+ {
+ _logger.Log(GetLogLevel(severity), message, paramList);
+ }
+
+ /// <summary>
+ /// Fatals the specified message.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public void Fatal(string message, params object[] paramList)
+ {
+ _logger.Fatal(message, paramList);
+ }
+
+ /// <summary>
+ /// Fatals the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="paramList">The param list.</param>
+ public void FatalException(string message, Exception exception, params object[] paramList)
+ {
+ LogException(LogSeverity.Fatal, message, exception, paramList);
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Logging/TraceFileLogger.cs b/MediaBrowser.Common/Logging/TraceFileLogger.cs
deleted file mode 100644
index 7ab67a137e..0000000000
--- a/MediaBrowser.Common/Logging/TraceFileLogger.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using MediaBrowser.Common.Kernel;
-using System;
-using System.ComponentModel.Composition;
-using System.Diagnostics;
-using System.IO;
-
-namespace MediaBrowser.Common.Logging
-{
- [Export(typeof(BaseLogger))]
- public class TraceFileLogger : BaseLogger
- {
- private TraceListener Listener { get; set; }
-
- public override void Initialize(IKernel kernel)
- {
- DateTime now = DateTime.Now;
-
- string logFilePath = Path.Combine(kernel.ApplicationPaths.LogDirectoryPath, "log-" + now.ToString("dMyyyy") + "-" + now.Ticks + ".log");
-
- Listener = new TextWriterTraceListener(logFilePath);
- Trace.Listeners.Add(Listener);
- Trace.AutoFlush = true;
- }
-
- public override void Dispose()
- {
- base.Dispose();
-
- Trace.Listeners.Remove(Listener);
- Listener.Dispose();
- }
-
- public override void LogEntry(LogRow row)
- {
- Trace.WriteLine(row.ToString());
- }
- }
-}
diff --git a/MediaBrowser.Common/Logging/WindowTraceListener.cs b/MediaBrowser.Common/Logging/WindowTraceListener.cs
new file mode 100644
index 0000000000..046dedf86e
--- /dev/null
+++ b/MediaBrowser.Common/Logging/WindowTraceListener.cs
@@ -0,0 +1,75 @@
+using System.Diagnostics;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class WindowTraceListener
+ /// </summary>
+ public class WindowTraceListener : DefaultTraceListener
+ {
+ /// <summary>
+ /// The _window
+ /// </summary>
+ private readonly LogWindow _window;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="WindowTraceListener" /> class.
+ /// </summary>
+ /// <param name="window">The window.</param>
+ public WindowTraceListener(LogWindow window)
+ {
+ _window = window;
+ _window.Show();
+ Name = "MBLogWindow";
+ }
+
+ /// <summary>
+ /// Writes the value of the object's <see cref="M:System.Object.ToString" /> method to the listener you create when you implement the <see cref="T:System.Diagnostics.TraceListener" /> class.
+ /// </summary>
+ /// <param name="o">An <see cref="T:System.Object" /> whose fully qualified class name you want to write.</param>
+ public override void Write(object o)
+ {
+ var str = o as string;
+ if (str != null)
+ Write(str);
+ else
+ base.Write(o);
+ }
+
+ /// <summary>
+ /// Writes the output to the OutputDebugString function and to the <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" /> method.
+ /// </summary>
+ /// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
+ /// <PermissionSet>
+ /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
+ /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
+ /// </PermissionSet>
+ public override void Write(string message)
+ {
+ _window.LogMessage(message);
+ }
+
+ /// <summary>
+ /// Writes the output to the OutputDebugString function and to the <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" /> method, followed by a carriage return and line feed (\r\n).
+ /// </summary>
+ /// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
+ /// <PermissionSet>
+ /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
+ /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
+ /// </PermissionSet>
+ public override void WriteLine(string message)
+ {
+ Write(message+"\n");
+ }
+
+ /// <summary>
+ /// Releases the unmanaged resources used by the <see cref="T:System.Diagnostics.TraceListener" /> and optionally releases the managed resources.
+ /// </summary>
+ /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (_window != null)
+ _window.ShutDown();
+ base.Dispose(disposing);
+ }
+ }
+}