aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Logging/WindowTraceListener.cs
blob: 042936ed18044c5921d8e963c09423dd8c522406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Diagnostics;

namespace MediaBrowser.ServerApplication.Logging
{
    /// <summary>
    /// Class WindowTraceListener
    /// </summary>
    public class WindowTraceListener : DefaultTraceListener
    {
        /// <summary>
        /// The _window
        /// </summary>
        private readonly LogForm _window;
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowTraceListener" /> class.
        /// </summary>
        /// <param name="window">The window.</param>
        public WindowTraceListener(LogForm 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);
        }
    }
}