ILogger.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System;
  2. namespace Best.HTTP.Shared.Logger
  3. {
  4. [HideFromDocumentation]
  5. public sealed class HideFromDocumentation : Attribute
  6. {
  7. }
  8. /// <summary>
  9. /// Available logging levels.
  10. /// </summary>
  11. public enum Loglevels : int
  12. {
  13. /// <summary>
  14. /// All message will be logged.
  15. /// </summary>
  16. All,
  17. /// <summary>
  18. /// Only Informations and above will be logged.
  19. /// </summary>
  20. Information,
  21. /// <summary>
  22. /// Only Warnings and above will be logged.
  23. /// </summary>
  24. Warning,
  25. /// <summary>
  26. /// Only Errors and above will be logged.
  27. /// </summary>
  28. Error,
  29. /// <summary>
  30. /// Only Exceptions will be logged.
  31. /// </summary>
  32. Exception,
  33. /// <summary>
  34. /// No logging will occur.
  35. /// </summary>
  36. None
  37. }
  38. /// <summary>
  39. /// Represents an output target for log messages.
  40. /// </summary>
  41. /// <remarks>
  42. /// <para>
  43. /// This interface defines methods for writing log messages to an output target.
  44. /// Implementations of this interface are used to configure where log messages
  45. /// should be written.
  46. /// </para>
  47. /// <para>
  48. /// Two of its out-of-the-box implementations are
  49. /// <list type="bullet">
  50. /// <item><description><see cref="UnityOutput">UnityOutput</see></description></item>
  51. /// <item><description><see cref="FileOutput">FileOutput</see></description></item>
  52. /// </list>
  53. /// </para>
  54. /// </remarks>
  55. public interface ILogOutput : IDisposable
  56. {
  57. /// <summary>
  58. /// Gets a value indicating whether the log output supports colored text.
  59. /// </summary>
  60. bool AcceptColor { get; }
  61. /// <summary>
  62. /// Writes a log entry to the output.
  63. /// </summary>
  64. /// <param name="level">The logging level of the entry.</param>
  65. /// <param name="logEntry">The log message to write.</param>
  66. void Write(Loglevels level, string logEntry);
  67. /// <summary>
  68. /// Flushes any buffered log entries to the output.
  69. /// </summary>
  70. void Flush();
  71. }
  72. /// <summary>
  73. /// Represents a filter for further sort out what log entries to include in the final log output.
  74. /// </summary>
  75. public interface IFilter
  76. {
  77. /// <summary>
  78. /// Return <c>true</c> if the division must be included in the output.
  79. /// </summary>
  80. bool Include(string division);
  81. }
  82. /// <summary>
  83. /// Represents a logger for recording log messages.
  84. /// </summary>
  85. public interface ILogger
  86. {
  87. /// <summary>
  88. /// Gets or sets the minimum severity level for logging.
  89. /// </summary>
  90. Loglevels Level { get; set; }
  91. /// <summary>
  92. /// Gets or sets the output target for log messages.
  93. /// </summary>
  94. /// <value>
  95. /// The <see cref="ILogOutput"/> instance used to write log messages.
  96. /// </value>
  97. ILogOutput Output { get; set; }
  98. /// <summary>
  99. /// Gets or sets an output filter to decide what messages are included or not.
  100. /// </summary>
  101. /// <value>The <see cref="IFilter"/> instance used for filtering.</value>
  102. IFilter Filter { get; set; }
  103. /// <summary>
  104. /// Property indicating whether the logger's internal queue is empty or not.
  105. /// </summary>
  106. bool IsEmpty { get; }
  107. /// <summary>
  108. /// Gets a value indicating whether diagnostic logging is enabled.
  109. /// </summary>
  110. /// <remarks>
  111. /// Diagnostic logging is enabled when <see cref="Level"/> is set to <see cref="Loglevels.All"/>.
  112. /// </remarks>
  113. bool IsDiagnostic { get; }
  114. /// <summary>
  115. /// Logs a message with <see cref="Loglevels.All"/> level.
  116. /// </summary>
  117. /// <param name="division">The division or category of the log message.</param>
  118. /// <param name="msg">The verbose log message.</param>
  119. /// <param name="context">The optional <see cref="LoggingContext"/> for additional context.</param>
  120. void Verbose(string division, string msg, LoggingContext context = null);
  121. /// <summary>
  122. /// Logs a message with <see cref="Loglevels.Information"/> level.
  123. /// </summary>
  124. /// <param name="division">The division or category of the log message.</param>
  125. /// <param name="msg">The verbose log message.</param>
  126. /// <param name="context">The optional <see cref="LoggingContext"/> for additional context.</param>
  127. void Information(string division, string msg, LoggingContext context = null);
  128. /// <summary>
  129. /// Logs a message with <see cref="Loglevels.Warning"/> level.
  130. /// </summary>
  131. /// <param name="division">The division or category of the log message.</param>
  132. /// <param name="msg">The verbose log message.</param>
  133. /// <param name="context">The optional <see cref="LoggingContext"/> for additional context.</param>
  134. void Warning(string division, string msg, LoggingContext context = null);
  135. /// <summary>
  136. /// Logs a message with <see cref="Loglevels.Error"/> level.
  137. /// </summary>
  138. /// <param name="division">The division or category of the log message.</param>
  139. /// <param name="msg">The verbose log message.</param>
  140. /// <param name="context">The optional <see cref="LoggingContext"/> for additional context.</param>
  141. void Error(string division, string msg, LoggingContext context = null);
  142. /// <summary>
  143. /// Logs a message with <see cref="Loglevels.Exception"/> level.
  144. /// </summary>
  145. /// <param name="division">The division or category of the log message.</param>
  146. /// <param name="msg">The verbose log message.</param>
  147. /// <param name="context">The optional <see cref="LoggingContext"/> for additional context.</param>
  148. void Exception(string division, string msg, Exception ex, LoggingContext context = null);
  149. }
  150. }