ChainloaderLogHelper.cs 1.4 KB

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