Logger.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Runtime.CompilerServices;
  2. namespace BepInEx
  3. {
  4. /// <summary>
  5. /// A helper class to use for logging.
  6. /// </summary>
  7. public static class BepInLogger
  8. {
  9. /// <summary>
  10. /// The handler for a entry logged event.
  11. /// </summary>
  12. /// <param name="entry">The text element of the log itself.</param>
  13. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  14. public delegate void EntryLoggedEventHandler(string entry, bool show = false);
  15. /// <summary>
  16. /// The listener event for an entry being logged.
  17. /// </summary>
  18. public static event EntryLoggedEventHandler EntryLogged;
  19. /// <summary>
  20. /// Logs an entry to the logger, and any listeners are notified of the entry.
  21. /// </summary>
  22. /// <param name="entry">The text element of the log itself.</param>
  23. /// <param name="show">Whether or not it should be dislpayed to the user.</param>
  24. public static void Log(string entry, bool show = false)
  25. {
  26. UnityEngine.UnityLogWriter.WriteStringToUnityLog($"BEPIN - {entry}\r\n");
  27. EntryLogged?.Invoke(entry, show);
  28. }
  29. }
  30. }
  31. namespace UnityEngine
  32. {
  33. internal sealed class UnityLogWriter
  34. {
  35. [MethodImpl(MethodImplOptions.InternalCall)]
  36. public static extern void WriteStringToUnityLog(string s);
  37. }
  38. }