You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. #if !NET20
  2. using System;
  3. namespace Apewer.WebSocket
  4. {
  5. /// <summary></summary>
  6. public enum LogLevel
  7. {
  8. /// <summary></summary>
  9. Debug = 0,
  10. /// <summary></summary>
  11. Info = 1,
  12. /// <summary></summary>
  13. Warn = 2,
  14. /// <summary></summary>
  15. Error = 3
  16. }
  17. internal class WebSocketLog
  18. {
  19. public static LogLevel Level = LogLevel.Info;
  20. public static Action<LogLevel, string, Exception> LogAction = (level, message, ex) =>
  21. {
  22. if (level >= Level) Console.WriteLine("{0} [{1}] {2} {3}", DateTime.Now, level, message, ex);
  23. };
  24. public static void Warn(string message, Exception ex = null)
  25. {
  26. LogAction(LogLevel.Warn, message, ex);
  27. }
  28. public static void Error(string message, Exception ex = null)
  29. {
  30. LogAction(LogLevel.Error, message, ex);
  31. }
  32. public static void Debug(string message, Exception ex = null)
  33. {
  34. LogAction(LogLevel.Debug, message, ex);
  35. }
  36. public static void Info(string message, Exception ex = null)
  37. {
  38. LogAction(LogLevel.Info, message, ex);
  39. }
  40. }
  41. }
  42. #endif