BepInLogger.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BepInEx.ConsoleUtil;
  4. namespace BepInEx
  5. {
  6. /// <summary>
  7. /// A helper class to use for logging.
  8. /// </summary>
  9. [Obsolete("This class has been deprecated; please use the Logger static class and BaseLogger implementations", true)]
  10. public static class BepInLogger
  11. {
  12. /// <summary>
  13. /// The handler for a entry logged event.
  14. /// </summary>
  15. /// <param name="entry">The text element of the log itself.</param>
  16. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  17. public delegate void EntryLoggedEventHandler(string entry, bool show = false);
  18. /// <summary>
  19. /// The listener event for an entry being logged.
  20. /// </summary>
  21. public static event EntryLoggedEventHandler EntryLogged;
  22. /// <summary>
  23. /// Logs an entry to the logger, and any listeners are notified of the entry.
  24. /// </summary>
  25. /// <param name="entry">The text element of the log itself.</param>
  26. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  27. public static void Log(string entry, bool show = false)
  28. {
  29. Log(entry, show, ConsoleColor.Gray);
  30. }
  31. /// <summary>
  32. /// Logs an entry to the logger, and any listeners are notified of the entry.
  33. /// </summary>
  34. /// <param name="entry">The text element of the log itself. Uses .ToString().</param>
  35. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  36. /// <param name="color">The color of the text to show in the console.</param>
  37. public static void Log(object entry, bool show, ConsoleColor color)
  38. {
  39. Log(entry.ToString(), show, color);
  40. }
  41. /// <summary>
  42. /// Logs an entry to the logger, and any listeners are notified of the entry.
  43. /// </summary>
  44. /// <param name="entry">The text element of the log itself.</param>
  45. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  46. /// <param name="color">The color of the text to show in the console.</param>
  47. public static void Log(string entry, bool show, ConsoleColor color)
  48. {
  49. UnityEngine.UnityLogWriter.WriteStringToUnityLog($"BEPIN - {entry}\r\n");
  50. Kon.ForegroundColor = color;
  51. Console.WriteLine(entry);
  52. EntryLogged?.Invoke(entry, show);
  53. }
  54. }
  55. }