ChainloaderLogHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Linq;
  2. using BepInEx.Logging;
  3. using BepInEx.Shared;
  4. using MonoMod.Utils;
  5. namespace BepInEx.Preloader.Core.Logging
  6. {
  7. public static class ChainloaderLogHelper
  8. {
  9. public static void PrintLogInfo(ManualLogSource log)
  10. {
  11. string consoleTitle = $"BepInEx {Paths.BepInExVersion} - {Paths.ProcessName}";
  12. log.LogMessage(consoleTitle);
  13. if (ConsoleManager.ConsoleActive)
  14. ConsoleManager.SetConsoleTitle(consoleTitle);
  15. //See BuildInfoAttribute for more information about this section.
  16. object[] attributes = typeof(BuildInfoAttribute).Assembly.GetCustomAttributes(typeof(BuildInfoAttribute), false);
  17. if (attributes.Length > 0)
  18. {
  19. var attribute = (BuildInfoAttribute)attributes[0];
  20. log.LogMessage(attribute.Info);
  21. }
  22. Logger.LogInfo($"System platform: {PlatformHelper.Current}");
  23. }
  24. public static void RewritePreloaderLogs()
  25. {
  26. if (PreloaderConsoleListener.LogEvents == null || PreloaderConsoleListener.LogEvents.Count == 0)
  27. return;
  28. // Temporarily disable the console log listener as we replay the preloader logs
  29. var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);
  30. if (logListener != null)
  31. Logger.Listeners.Remove(logListener);
  32. foreach (var preloaderLogEvent in PreloaderConsoleListener.LogEvents)
  33. {
  34. Logger.InternalLogEvent(PreloaderLogger.Log, preloaderLogEvent);
  35. }
  36. if (logListener != null)
  37. Logger.Listeners.Add(logListener);
  38. }
  39. }
  40. }