From fdafa596832eae13cebcf5bbe5fa867f7ba068f0 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 21 Feb 2013 20:26:35 -0500 Subject: Removed System.Windows.Forms dependancy from Common. Almost done removing NLog dependancy. --- MediaBrowser.Common/Logging/LogHelper.cs | 90 --------- MediaBrowser.Common/Logging/LogManager.cs | 20 -- MediaBrowser.Common/Logging/LogWindow.xaml | 8 - MediaBrowser.Common/Logging/LogWindow.xaml.cs | 128 ------------- MediaBrowser.Common/Logging/NLogger.cs | 201 --------------------- MediaBrowser.Common/Logging/WindowTraceListener.cs | 75 -------- 6 files changed, 522 deletions(-) delete mode 100644 MediaBrowser.Common/Logging/LogHelper.cs delete mode 100644 MediaBrowser.Common/Logging/LogManager.cs delete mode 100644 MediaBrowser.Common/Logging/LogWindow.xaml delete mode 100644 MediaBrowser.Common/Logging/LogWindow.xaml.cs delete mode 100644 MediaBrowser.Common/Logging/NLogger.cs delete mode 100644 MediaBrowser.Common/Logging/WindowTraceListener.cs (limited to 'MediaBrowser.Common/Logging') 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 -{ - /// - /// Class LogHelper - /// - public static class LogHelper - { - /// - /// Gets the log message. - /// - /// The exception. - /// StringBuilder. - 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; - } - - /// - /// Appends the inner exceptions. - /// - /// The message text. - /// The e. - 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); - } - } - - /// - /// Appends the inner exception. - /// - /// The message text. - /// The e. - 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); - } - } - - /// - /// Logs the exception data. - /// - /// The message text. - /// The e. - 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 -{ - /// - /// Class LogManager - /// - public static class LogManager - { - /// - /// Gets the logger. - /// - /// The name. - /// ILogger. - 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 @@ - - - - - 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 -{ - /// - /// Interaction logic for LogWindow.xaml - /// - public partial class LogWindow : Window - { - /// - /// The _ui thread - /// - private readonly TaskScheduler _uiThread; - /// - /// The _kernel - /// - private readonly IKernel _kernel; - - /// - /// Initializes a new instance of the class. - /// - /// The kernel. - public LogWindow(IKernel kernel) - { - InitializeComponent(); - _uiThread = TaskScheduler.FromCurrentSynchronizationContext(); - _kernel = kernel; - - Loaded += LogWindow_Loaded; - } - - /// - /// Handles the Loaded event of the LogWindow control. - /// - /// The source of the event. - /// The instance containing the event data. - void LogWindow_Loaded(object sender, RoutedEventArgs e) - { - var target = new TraceTarget - { - Layout = "${longdate}, ${level}, ${logger}, ${message}" - }; - - AddLogTarget(target, "LogWindowTraceTarget"); - } - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnClosing(CancelEventArgs e) - { - base.OnClosing(e); - - RemoveLogTarget("LogWindowTraceTarget"); - } - - /// - /// Logs the message. - /// - /// The MSG. - public async void LogMessage(string msg) - { - await Task.Factory.StartNew(() => lbxLogData.Items.Insert(0, msg.TrimEnd('\n')), CancellationToken.None, TaskCreationOptions.None, _uiThread); - } - - /// - /// The log layout - /// - /// The log layout. - public string LogLayout - { - get { return "${longdate}, ${level}, ${logger}, ${message}"; } - } - - /// - /// Adds the log target. - /// - /// The target. - /// The name. - 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; - } - - /// - /// 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. - /// - 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 -{ - /// - /// Class NLogger - /// - internal class NLogger : ILogger - { - /// - /// The _logger - /// - private readonly NLog.Logger _logger; - - /// - /// The _lock object - /// - private static readonly object LockObject = new object(); - - /// - /// Initializes a new instance of the class. - /// - /// The name. - public NLogger(string name) - { - lock (LockObject) - { - _logger = NLog.LogManager.GetLogger(name); - } - } - - /// - /// Infoes the specified message. - /// - /// The message. - /// The param list. - public void Info(string message, params object[] paramList) - { - _logger.Info(message, paramList); - } - - /// - /// Errors the specified message. - /// - /// The message. - /// The param list. - public void Error(string message, params object[] paramList) - { - _logger.Error(message, paramList); - } - - /// - /// Warns the specified message. - /// - /// The message. - /// The param list. - public void Warn(string message, params object[] paramList) - { - _logger.Warn(message, paramList); - } - - /// - /// Debugs the specified message. - /// - /// The message. - /// The param list. - public void Debug(string message, params object[] paramList) - { - _logger.Debug(message, paramList); - } - - /// - /// Logs the exception. - /// - /// The message. - /// The exception. - /// The param list. - /// - public void ErrorException(string message, Exception exception, params object[] paramList) - { - LogException(LogSeverity.Error, message, exception, paramList); - } - - /// - /// Logs the exception. - /// - /// The level. - /// The message. - /// The exception. - /// The param list. - 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); - } - - /// - /// Formats the message. - /// - /// The message. - /// The param list. - /// System.String. - 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; - } - - /// - /// Logs the multiline. - /// - /// The message. - /// The severity. - /// Content of the additional. - 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); - } - - /// - /// Gets the log level. - /// - /// The severity. - /// NLog.LogLevel. - 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()); - } - } - - /// - /// Logs the specified severity. - /// - /// The severity. - /// The message. - /// The param list. - public void Log(LogSeverity severity, string message, params object[] paramList) - { - _logger.Log(GetLogLevel(severity), message, paramList); - } - - /// - /// Fatals the specified message. - /// - /// The message. - /// The param list. - public void Fatal(string message, params object[] paramList) - { - _logger.Fatal(message, paramList); - } - - /// - /// Fatals the exception. - /// - /// The message. - /// The exception. - /// The param list. - 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 -{ - /// - /// Class WindowTraceListener - /// - public class WindowTraceListener : DefaultTraceListener - { - /// - /// The _window - /// - private readonly LogWindow _window; - /// - /// Initializes a new instance of the class. - /// - /// The window. - public WindowTraceListener(LogWindow window) - { - _window = window; - _window.Show(); - Name = "MBLogWindow"; - } - - /// - /// Writes the value of the object's method to the listener you create when you implement the class. - /// - /// An whose fully qualified class name you want to write. - public override void Write(object o) - { - var str = o as string; - if (str != null) - Write(str); - else - base.Write(o); - } - - /// - /// Writes the output to the OutputDebugString function and to the method. - /// - /// The message to write to OutputDebugString and . - /// - /// - /// - /// - public override void Write(string message) - { - _window.LogMessage(message); - } - - /// - /// Writes the output to the OutputDebugString function and to the method, followed by a carriage return and line feed (\r\n). - /// - /// The message to write to OutputDebugString and . - /// - /// - /// - /// - public override void WriteLine(string message) - { - Write(message+"\n"); - } - - /// - /// Releases the unmanaged resources used by the and optionally releases the managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool disposing) - { - if (_window != null) - _window.ShutDown(); - base.Dispose(disposing); - } - } -} -- cgit v1.2.3