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);
}
}
}