aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Logging
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-21 20:26:35 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-21 20:26:35 -0500
commitfdafa596832eae13cebcf5bbe5fa867f7ba068f0 (patch)
treeeee891c8f11564d4b14868d11f4758f243c112ce /MediaBrowser.Common/Logging
parent931c0ea455161b8ee00005a0ffd1f8afab41f7bb (diff)
Removed System.Windows.Forms dependancy from Common. Almost done removing NLog dependancy.
Diffstat (limited to 'MediaBrowser.Common/Logging')
-rw-r--r--MediaBrowser.Common/Logging/LogHelper.cs90
-rw-r--r--MediaBrowser.Common/Logging/LogManager.cs20
-rw-r--r--MediaBrowser.Common/Logging/LogWindow.xaml8
-rw-r--r--MediaBrowser.Common/Logging/LogWindow.xaml.cs128
-rw-r--r--MediaBrowser.Common/Logging/NLogger.cs201
-rw-r--r--MediaBrowser.Common/Logging/WindowTraceListener.cs75
6 files changed, 0 insertions, 522 deletions
diff --git a/MediaBrowser.Common/Logging/LogHelper.cs b/MediaBrowser.Common/Logging/LogHelper.cs
deleted file mode 100644
index 8b638a28e..000000000
--- a/MediaBrowser.Common/Logging/LogHelper.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-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
deleted file mode 100644
index 825f04440..000000000
--- a/MediaBrowser.Common/Logging/LogManager.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-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/LogWindow.xaml b/MediaBrowser.Common/Logging/LogWindow.xaml
deleted file mode 100644
index 726d3c968..000000000
--- a/MediaBrowser.Common/Logging/LogWindow.xaml
+++ /dev/null
@@ -1,8 +0,0 @@
-<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
deleted file mode 100644
index 3dc11db5b..000000000
--- a/MediaBrowser.Common/Logging/LogWindow.xaml.cs
+++ /dev/null
@@ -1,128 +0,0 @@
-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/NLogger.cs b/MediaBrowser.Common/Logging/NLogger.cs
deleted file mode 100644
index 584c5616b..000000000
--- a/MediaBrowser.Common/Logging/NLogger.cs
+++ /dev/null
@@ -1,201 +0,0 @@
-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/WindowTraceListener.cs b/MediaBrowser.Common/Logging/WindowTraceListener.cs
deleted file mode 100644
index 046dedf86..000000000
--- a/MediaBrowser.Common/Logging/WindowTraceListener.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-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);
- }
- }
-}