Logger.cs 1.4 KB

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