1
0

ILogWriter.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Runtime.CompilerServices;
  2. namespace OSHttpServer
  3. {
  4. /// <summary>
  5. /// Priority for log entries
  6. /// </summary>
  7. /// <seealso cref="ILogWriter"/>
  8. public enum LogPrio
  9. {
  10. None,
  11. /// <summary>
  12. /// Very detailed logs to be able to follow the flow of the program.
  13. /// </summary>
  14. Trace,
  15. /// <summary>
  16. /// Logs to help debug errors in the application
  17. /// </summary>
  18. Debug,
  19. /// <summary>
  20. /// Information to be able to keep track of state changes etc.
  21. /// </summary>
  22. Info,
  23. /// <summary>
  24. /// Something did not go as we expected, but it's no problem.
  25. /// </summary>
  26. Warning,
  27. /// <summary>
  28. /// Something that should not fail failed, but we can still keep
  29. /// on going.
  30. /// </summary>
  31. Error,
  32. /// <summary>
  33. /// Something failed, and we cannot handle it properly.
  34. /// </summary>
  35. Fatal
  36. }
  37. /// <summary>
  38. /// Interface used to write to log files.
  39. /// </summary>
  40. public interface ILogWriter
  41. {
  42. /// <summary>
  43. /// Write an entry to the log file.
  44. /// </summary>
  45. /// <param name="source">object that is writing to the log</param>
  46. /// <param name="priority">importance of the log message</param>
  47. /// <param name="message">the message</param>
  48. void Write(object source, LogPrio priority, string message);
  49. }
  50. /// <summary>
  51. /// Default log writer, writes everything to null (nowhere).
  52. /// </summary>
  53. /// <seealso cref="ILogWriter"/>
  54. public sealed class NullLogWriter : ILogWriter
  55. {
  56. /// <summary>
  57. /// The logging instance.
  58. /// </summary>
  59. public static readonly NullLogWriter Instance = new();
  60. /// <summary>
  61. /// Writes everything to null
  62. /// </summary>
  63. /// <param name="source">object that wrote the log entry.</param>
  64. /// <param name="prio">Importance of the log message</param>
  65. /// <param name="message">The message.</param>
  66. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  67. public void Write(object source, LogPrio prio, string message) {}
  68. }
  69. }