IL2CPPUnityLogSource.cs 998 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extern alias il2cpp;
  2. using System;
  3. using BepInEx.Logging;
  4. using il2cpp::UnityEngine;
  5. namespace BepInEx.IL2CPP.Logging
  6. {
  7. public class IL2CPPUnityLogSource : ILogSource
  8. {
  9. public string SourceName { get; } = "Unity";
  10. public event EventHandler<LogEventArgs> LogEvent;
  11. public void UnityLogCallback(string logLine, string exception, LogType type)
  12. {
  13. LogLevel level = LogLevel.Message;
  14. switch (type)
  15. {
  16. case LogType.Error:
  17. level = LogLevel.Error;
  18. break;
  19. case LogType.Assert:
  20. level = LogLevel.Debug;
  21. break;
  22. case LogType.Warning:
  23. level = LogLevel.Warning;
  24. break;
  25. case LogType.Log:
  26. level = LogLevel.Message;
  27. break;
  28. case LogType.Exception:
  29. level = LogLevel.Error;
  30. break;
  31. }
  32. LogEvent?.Invoke(this, new LogEventArgs(logLine, level, this));
  33. }
  34. public IL2CPPUnityLogSource()
  35. {
  36. Application.s_LogCallbackHandler = new Action<string, string, LogType>(UnityLogCallback);
  37. }
  38. public void Dispose() { }
  39. }
  40. }