2
0

WindowTraceListener.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Diagnostics;
  2. namespace MediaBrowser.ServerApplication.Logging
  3. {
  4. /// <summary>
  5. /// Class WindowTraceListener
  6. /// </summary>
  7. public class WindowTraceListener : DefaultTraceListener
  8. {
  9. /// <summary>
  10. /// The _window
  11. /// </summary>
  12. private readonly LogWindow _window;
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="WindowTraceListener" /> class.
  15. /// </summary>
  16. /// <param name="window">The window.</param>
  17. public WindowTraceListener(LogWindow window)
  18. {
  19. _window = window;
  20. _window.Show();
  21. Name = "MBLogWindow";
  22. }
  23. /// <summary>
  24. /// 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.
  25. /// </summary>
  26. /// <param name="o">An <see cref="T:System.Object" /> whose fully qualified class name you want to write.</param>
  27. public override void Write(object o)
  28. {
  29. var str = o as string;
  30. if (str != null)
  31. Write(str);
  32. else
  33. base.Write(o);
  34. }
  35. /// <summary>
  36. /// Writes the output to the OutputDebugString function and to the <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" /> method.
  37. /// </summary>
  38. /// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
  39. /// <PermissionSet>
  40. /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  41. /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
  42. /// </PermissionSet>
  43. public override void Write(string message)
  44. {
  45. _window.LogMessage(message);
  46. }
  47. /// <summary>
  48. /// 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).
  49. /// </summary>
  50. /// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
  51. /// <PermissionSet>
  52. /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  53. /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
  54. /// </PermissionSet>
  55. public override void WriteLine(string message)
  56. {
  57. Write(message+"\n");
  58. }
  59. /// <summary>
  60. /// Releases the unmanaged resources used by the <see cref="T:System.Diagnostics.TraceListener" /> and optionally releases the managed resources.
  61. /// </summary>
  62. /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
  63. protected override void Dispose(bool disposing)
  64. {
  65. if (_window != null)
  66. _window.ShutDown();
  67. base.Dispose(disposing);
  68. }
  69. }
  70. }