PreloaderConsoleListener.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections.Generic;
  2. using BepInEx.Configuration;
  3. using BepInEx.Logging;
  4. namespace BepInEx.Preloader.Core.Logging
  5. {
  6. /// <summary>
  7. /// Log listener that listens to logs during preloading time and buffers messages for output in Unity logs later.
  8. /// </summary>
  9. public class PreloaderConsoleListener : ILogListener
  10. {
  11. /// <summary>
  12. /// A list of all <see cref="LogEventArgs"/> objects that this listener has received.
  13. /// </summary>
  14. public static List<LogEventArgs> LogEvents { get; } = new List<LogEventArgs>();
  15. /// <inheritdoc />
  16. public void LogEvent(object sender, LogEventArgs eventArgs)
  17. {
  18. if ((eventArgs.Level & ConfigConsoleDisplayedLevel.Value) == 0)
  19. return;
  20. LogEvents.Add(eventArgs);
  21. }
  22. private static readonly ConfigEntry<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Bind(
  23. "Logging.Console", "LogLevels",
  24. LogLevel.Fatal | LogLevel.Error | LogLevel.Warning | LogLevel.Message | LogLevel.Info,
  25. "Which log levels to show in the console output.");
  26. /// <inheritdoc />
  27. public void Dispose() { }
  28. }
  29. }