Trace.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (c) 2013, 2014 Paolo Patierno
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. http://www.eclipse.org/legal/epl-v10.html
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. Contributors:
  11. Paolo Patierno - initial API and implementation and/or initial documentation
  12. */
  13. using System.Diagnostics;
  14. namespace uPLibrary.Networking.M2Mqtt.Utility
  15. {
  16. /// <summary>
  17. /// Tracing levels
  18. /// </summary>
  19. public enum TraceLevel
  20. {
  21. Error = 0x01,
  22. Warning = 0x02,
  23. Information = 0x04,
  24. Verbose = 0x0F,
  25. Frame = 0x10,
  26. Queuing = 0x20
  27. }
  28. // delegate for writing trace
  29. public delegate void WriteTrace(string format, params object[] args);
  30. /// <summary>
  31. /// Tracing class
  32. /// </summary>
  33. public static class Trace
  34. {
  35. public static TraceLevel TraceLevel;
  36. public static WriteTrace TraceListener;
  37. [Conditional("DEBUG")]
  38. public static void Debug(string format, params object[] args)
  39. {
  40. if (TraceListener != null)
  41. {
  42. TraceListener(format, args);
  43. }
  44. }
  45. public static void WriteLine(TraceLevel level, string format)
  46. {
  47. if (TraceListener != null && (level & TraceLevel) > 0)
  48. {
  49. TraceListener(format);
  50. }
  51. }
  52. public static void WriteLine(TraceLevel level, string format, object arg1)
  53. {
  54. if (TraceListener != null && (level & TraceLevel) > 0)
  55. {
  56. TraceListener(format, arg1);
  57. }
  58. }
  59. public static void WriteLine(TraceLevel level, string format, object arg1, object arg2)
  60. {
  61. if (TraceListener != null && (level & TraceLevel) > 0)
  62. {
  63. TraceListener(format, arg1, arg2);
  64. }
  65. }
  66. public static void WriteLine(TraceLevel level, string format, object arg1, object arg2, object arg3)
  67. {
  68. if (TraceListener != null && (level & TraceLevel) > 0)
  69. {
  70. TraceListener(format, arg1, arg2, arg3);
  71. }
  72. }
  73. }
  74. }