ConsoleLogListener.cs 1006 B

12345678910111213141516171819202122232425262728293031323334
  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. protected LogLevel DisplayedLogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), ConfigConsoleDisplayedLevel.Value, true);
  12. public void LogEvent(object sender, LogEventArgs eventArgs)
  13. {
  14. if (eventArgs.Level.GetHighestLevel() > DisplayedLogLevel)
  15. return;
  16. string log = $"[{eventArgs.Level, -7}:{((ILogSource)sender).SourceName, 10}] {eventArgs.Data}\r\n";
  17. Kon.ForegroundColor = eventArgs.Level.GetConsoleColor();
  18. Console.Write(log);
  19. Kon.ForegroundColor = ConsoleColor.Gray;
  20. }
  21. public void Dispose() { }
  22. private static readonly ConfigWrapper<string> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
  23. "Logging.Console",
  24. "DisplayedLogLevel",
  25. "Only displays the specified log level and above in the console output.",
  26. "Info");
  27. }
  28. }