LogLevel.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Linq;
  3. namespace BepInEx.Logging
  4. {
  5. [Flags]
  6. public enum LogLevel
  7. {
  8. None = 0,
  9. Fatal = 1,
  10. Error = 2,
  11. Warning = 4,
  12. Message = 8,
  13. Info = 16,
  14. Debug = 32,
  15. All = Fatal | Error | Warning | Message | Info | Debug
  16. }
  17. public static class LogLevelExtensions
  18. {
  19. public static LogLevel GetHighestLevel(this LogLevel levels)
  20. {
  21. var enums = Enum.GetValues(typeof(LogLevel));
  22. Array.Sort(enums);
  23. foreach (LogLevel e in enums)
  24. {
  25. if ((levels & e) != LogLevel.None)
  26. return e;
  27. }
  28. return LogLevel.None;
  29. }
  30. public static ConsoleColor GetConsoleColor(this LogLevel level)
  31. {
  32. level = GetHighestLevel(level);
  33. switch (level)
  34. {
  35. case LogLevel.Fatal:
  36. return ConsoleColor.Red;
  37. case LogLevel.Error:
  38. return ConsoleColor.DarkRed;
  39. case LogLevel.Warning:
  40. return ConsoleColor.Yellow;
  41. case LogLevel.Message:
  42. return ConsoleColor.White;
  43. case LogLevel.Info:
  44. default:
  45. return ConsoleColor.Gray;
  46. case LogLevel.Debug:
  47. return ConsoleColor.DarkGray;
  48. }
  49. }
  50. }
  51. }