ILogWriter.cs 2.2 KB

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