Tracer.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace Apache.NMS
  18. {
  19. public sealed class Tracer
  20. {
  21. private static ITrace s_trace = null;
  22. // prevent instantiation of this class. All methods are static.
  23. private Tracer()
  24. {
  25. }
  26. public static ITrace Trace
  27. {
  28. get { return s_trace; }
  29. set { s_trace = value; }
  30. }
  31. public static bool IsDebugEnabled
  32. {
  33. get { return s_trace != null && s_trace.IsDebugEnabled; }
  34. }
  35. public static bool IsInfoEnabled
  36. {
  37. get { return s_trace != null && s_trace.IsInfoEnabled; }
  38. }
  39. public static bool IsWarnEnabled
  40. {
  41. get { return s_trace != null && s_trace.IsWarnEnabled; }
  42. }
  43. public static bool IsErrorEnabled
  44. {
  45. get { return s_trace != null && s_trace.IsErrorEnabled; }
  46. }
  47. public static bool IsFatalEnabled
  48. {
  49. get { return s_trace != null && s_trace.IsFatalEnabled; }
  50. }
  51. public static void Debug(object message)
  52. {
  53. if (IsDebugEnabled)
  54. {
  55. s_trace.Debug(message.ToString());
  56. }
  57. }
  58. public static void DebugFormat(string format, params object[] args)
  59. {
  60. if (IsDebugEnabled)
  61. {
  62. s_trace.Debug(string.Format(format, args));
  63. }
  64. }
  65. public static void Info(object message)
  66. {
  67. if (IsInfoEnabled)
  68. {
  69. s_trace.Info(message.ToString());
  70. }
  71. }
  72. public static void InfoFormat(string format, params object[] args)
  73. {
  74. if (IsInfoEnabled)
  75. {
  76. s_trace.Info(string.Format(format, args));
  77. }
  78. }
  79. public static void Warn(object message)
  80. {
  81. if (IsWarnEnabled)
  82. {
  83. s_trace.Warn(message.ToString());
  84. }
  85. }
  86. public static void WarnFormat(string format, params object[] args)
  87. {
  88. if (IsWarnEnabled)
  89. {
  90. s_trace.Warn(string.Format(format, args));
  91. }
  92. }
  93. public static void Error(object message)
  94. {
  95. if (IsErrorEnabled)
  96. {
  97. s_trace.Error(message.ToString());
  98. }
  99. }
  100. public static void ErrorFormat(string format, params object[] args)
  101. {
  102. if (IsErrorEnabled)
  103. {
  104. s_trace.Error(string.Format(format, args));
  105. }
  106. }
  107. public static void Fatal(object message)
  108. {
  109. if (IsFatalEnabled)
  110. {
  111. s_trace.Fatal(message.ToString());
  112. }
  113. }
  114. public static void FatalFormat(string format, params object[] args)
  115. {
  116. if (IsFatalEnabled)
  117. {
  118. s_trace.Fatal(string.Format(format, args));
  119. }
  120. }
  121. }
  122. }