UnityLogWriter.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BepInEx.ConsoleUtil;
  4. namespace BepInEx.Logging
  5. {
  6. public class UnityLogWriter : BaseLogger
  7. {
  8. public void WriteToLog(string value)
  9. {
  10. UnityEngine.UnityLogWriter.WriteStringToUnityLog(value);
  11. }
  12. protected void InternalWrite(string value)
  13. {
  14. Console.Write(value);
  15. WriteToLog(value);
  16. }
  17. public override void Log(LogLevel level, object entry)
  18. {
  19. Kon.ForegroundColor = level.GetConsoleColor();
  20. base.Log(level, entry);
  21. Kon.ForegroundColor = ConsoleColor.Gray;
  22. }
  23. public override void WriteLine(string value) => InternalWrite($"{value}\r\n");
  24. public override void Write(char value) => InternalWrite(value.ToString());
  25. public override void Write(string value) => InternalWrite(value);
  26. }
  27. }
  28. namespace UnityEngine
  29. {
  30. internal sealed class UnityLogWriter
  31. {
  32. [MethodImpl(MethodImplOptions.InternalCall)]
  33. public static extern void WriteStringToUnityLog(string s);
  34. }
  35. }