Logger.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using BepInEx.Logging;
  2. namespace BepInEx
  3. {
  4. /// <summary>
  5. /// A static <see cref="BaseLogger"/> instance.
  6. /// </summary>
  7. public static class Logger
  8. {
  9. /// <summary>
  10. /// The current instance of a <see cref="BaseLogger"/> that is being used.
  11. /// </summary>
  12. public static BaseLogger CurrentLogger { get; set; }
  13. /// <summary>
  14. /// The listener event for an entry being logged.
  15. /// </summary>
  16. public static event BaseLogger.EntryLoggedEventHandler EntryLogged;
  17. /// <summary>
  18. /// Logs an entry to the current logger instance.
  19. /// </summary>
  20. /// <param name="level">The level of the entry.</param>
  21. /// <param name="entry">The textual value of the entry.</param>
  22. public static void Log(LogLevel level, object entry)
  23. {
  24. EntryLogged?.Invoke(level, entry);
  25. CurrentLogger?.Log(level, entry);
  26. }
  27. /// <summary>
  28. /// Sets the instance being used by the static <see cref="Logger"/> class.
  29. /// </summary>
  30. /// <param name="logger">The instance to use in the static class.</param>
  31. public static void SetLogger(BaseLogger logger)
  32. {
  33. CurrentLogger?.Dispose();
  34. CurrentLogger = logger;
  35. }
  36. }
  37. }