Logger.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace Nwc.XmlRpc
  2. {
  3. using System;
  4. /// <summary>Define levels of logging.</summary><remarks> This duplicates
  5. /// similar enumerations in System.Diagnostics.EventLogEntryType. The
  6. /// duplication was merited because .NET Compact Framework lacked the EventLogEntryType enum.</remarks>
  7. public enum LogLevel
  8. {
  9. /// <summary>Information level, log entry for informational reasons only.</summary>
  10. Information,
  11. /// <summary>Warning level, indicates a possible problem.</summary>
  12. Warning,
  13. /// <summary>Error level, implies a significant problem.</summary>
  14. Error
  15. }
  16. ///<summary>
  17. ///Logging singleton with swappable output delegate.
  18. ///</summary>
  19. ///<remarks>
  20. ///This singleton provides a centralized log. The actual WriteEntry calls are passed
  21. ///off to a delegate however. Having a delegate do the actual logginh allows you to
  22. ///implement different logging mechanism and have them take effect throughout the system.
  23. ///</remarks>
  24. public class Logger
  25. {
  26. ///<summary>Delegate definition for logging.</summary>
  27. ///<param name="message">The message <c>String</c> to log.</param>
  28. ///<param name="level">The <c>LogLevel</c> of your message.</param>
  29. public delegate void LoggerDelegate(String message, LogLevel level);
  30. ///<summary>The LoggerDelegate that will recieve WriteEntry requests.</summary>
  31. static public LoggerDelegate Delegate = null;
  32. ///<summary>
  33. ///Method logging events are sent to.
  34. ///</summary>
  35. ///<param name="message">The message <c>String</c> to log.</param>
  36. ///<param name="level">The <c>LogLevel</c> of your message.</param>
  37. static public void WriteEntry(String message, LogLevel level)
  38. {
  39. if (Delegate != null)
  40. Delegate(message, level);
  41. }
  42. }
  43. }