ChainloaderLogHelper.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Diagnostics;
  2. using System.IO;
  3. using System.Linq;
  4. using BepInEx.Logging;
  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 {typeof(Paths).Assembly.GetName().Version} - {Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().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. }
  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. }