ConsoleLogListener.cs 931 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using BepInEx.Configuration;
  3. using BepInEx.ConsoleUtil;
  4. namespace BepInEx.Logging
  5. {
  6. /// <summary>
  7. /// Logs entries using Unity specific outputs.
  8. /// </summary>
  9. public class ConsoleLogListener : ILogListener
  10. {
  11. public void LogEvent(object sender, LogEventArgs eventArgs)
  12. {
  13. if (eventArgs.Level.GetHighestLevel() > ConfigConsoleDisplayedLevel.Value)
  14. return;
  15. string log = $"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}\r\n";
  16. Kon.ForegroundColor = eventArgs.Level.GetConsoleColor();
  17. Console.Write(log);
  18. Kon.ForegroundColor = ConsoleColor.Gray;
  19. }
  20. public void Dispose() { }
  21. private static readonly ConfigWrapper<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.GetSetting(
  22. "Logging.Console","DisplayedLogLevel",
  23. LogLevel.Info,
  24. new ConfigDescription("Only displays the specified log level and above in the console output."));
  25. }
  26. }