LevelEvaluator.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #region Apache License
  2. //
  3. // Licensed to the Apache Software Foundation (ASF) under one or more
  4. // contributor license agreements. See the NOTICE file distributed with
  5. // this work for additional information regarding copyright ownership.
  6. // The ASF licenses this file to you under the Apache License, Version 2.0
  7. // (the "License"); you may not use this file except in compliance with
  8. // the License. You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. #endregion
  19. using System;
  20. using log4net;
  21. namespace log4net.Core
  22. {
  23. /// <summary>
  24. /// An evaluator that triggers at a threshold level
  25. /// </summary>
  26. /// <remarks>
  27. /// <para>
  28. /// This evaluator will trigger if the level of the event
  29. /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
  30. /// is equal to or greater than the <see cref="Threshold"/>
  31. /// level.
  32. /// </para>
  33. /// </remarks>
  34. /// <author>Nicko Cadell</author>
  35. public class LevelEvaluator : ITriggeringEventEvaluator
  36. {
  37. /// <summary>
  38. /// The threshold for triggering
  39. /// </summary>
  40. private Level m_threshold;
  41. /// <summary>
  42. /// Create a new evaluator using the <see cref="Level.Off"/> threshold.
  43. /// </summary>
  44. /// <remarks>
  45. /// <para>
  46. /// Create a new evaluator using the <see cref="Level.Off"/> threshold.
  47. /// </para>
  48. /// <para>
  49. /// This evaluator will trigger if the level of the event
  50. /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
  51. /// is equal to or greater than the <see cref="Threshold"/>
  52. /// level.
  53. /// </para>
  54. /// </remarks>
  55. public LevelEvaluator() : this(Level.Off)
  56. {
  57. }
  58. /// <summary>
  59. /// Create a new evaluator using the specified <see cref="Level"/> threshold.
  60. /// </summary>
  61. /// <param name="threshold">the threshold to trigger at</param>
  62. /// <remarks>
  63. /// <para>
  64. /// Create a new evaluator using the specified <see cref="Level"/> threshold.
  65. /// </para>
  66. /// <para>
  67. /// This evaluator will trigger if the level of the event
  68. /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
  69. /// is equal to or greater than the <see cref="Threshold"/>
  70. /// level.
  71. /// </para>
  72. /// </remarks>
  73. public LevelEvaluator(Level threshold)
  74. {
  75. if (threshold == null)
  76. {
  77. throw new ArgumentNullException("threshold");
  78. }
  79. m_threshold = threshold;
  80. }
  81. /// <summary>
  82. /// the threshold to trigger at
  83. /// </summary>
  84. /// <value>
  85. /// The <see cref="Level"/> that will cause this evaluator to trigger
  86. /// </value>
  87. /// <remarks>
  88. /// <para>
  89. /// This evaluator will trigger if the level of the event
  90. /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
  91. /// is equal to or greater than the <see cref="Threshold"/>
  92. /// level.
  93. /// </para>
  94. /// </remarks>
  95. public Level Threshold
  96. {
  97. get { return m_threshold; }
  98. set { m_threshold = value; }
  99. }
  100. /// <summary>
  101. /// Is this <paramref name="loggingEvent"/> the triggering event?
  102. /// </summary>
  103. /// <param name="loggingEvent">The event to check</param>
  104. /// <returns>This method returns <c>true</c>, if the event level
  105. /// is equal or higher than the <see cref="Threshold"/>.
  106. /// Otherwise it returns <c>false</c></returns>
  107. /// <remarks>
  108. /// <para>
  109. /// This evaluator will trigger if the level of the event
  110. /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
  111. /// is equal to or greater than the <see cref="Threshold"/>
  112. /// level.
  113. /// </para>
  114. /// </remarks>
  115. public bool IsTriggeringEvent(LoggingEvent loggingEvent)
  116. {
  117. if (loggingEvent == null)
  118. {
  119. throw new ArgumentNullException("loggingEvent");
  120. }
  121. return (loggingEvent.Level >= m_threshold);
  122. }
  123. }
  124. }