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. --- .../Logging/WindowTraceListener.cs | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs (limited to 'MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs') diff --git a/MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs b/MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs new file mode 100644 index 000000000..10d6ef812 --- /dev/null +++ b/MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs @@ -0,0 +1,75 @@ +using System.Diagnostics; + +namespace MediaBrowser.ServerApplication.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