ChainloaderLogHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Diagnostics;
  2. using System.Linq;
  3. using BepInEx.Logging;
  4. namespace BepInEx.Preloader.Core.Logging
  5. {
  6. public static class ChainloaderLogHelper
  7. {
  8. public static void PrintLogInfo(ManualLogSource log)
  9. {
  10. string consoleTile = $"BepInEx {typeof(Paths).Assembly.GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
  11. log.LogMessage(consoleTile);
  12. if (ConsoleManager.ConsoleActive)
  13. ConsoleManager.SetConsoleTitle(consoleTile);
  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. }
  22. public static void RewritePreloaderLogs()
  23. {
  24. if (PreloaderConsoleListener.LogEvents == null || PreloaderConsoleListener.LogEvents.Count == 0)
  25. return;
  26. // Temporarily disable the console log listener as we replay the preloader logs
  27. var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);
  28. if (logListener != null)
  29. Logger.Listeners.Remove(logListener);
  30. foreach (var preloaderLogEvent in PreloaderConsoleListener.LogEvents)
  31. {
  32. PreloaderLogger.Log.Log(preloaderLogEvent.Level, $"[{ preloaderLogEvent.Source.SourceName,10}] { preloaderLogEvent.Data}");
  33. }
  34. if (logListener != null)
  35. Logger.Listeners.Add(logListener);
  36. }
  37. }
  38. }