You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

  1. using IllusionPlugin.Logging;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using LoggerBase = IllusionPlugin.Logging.Logger;
  9. namespace IllusionInjector.Logging.Printers
  10. {
  11. class PluginLogFilePrinter : GZFilePrinter
  12. {
  13. public override LoggerBase.LogLevel Filter { get; set; } = LoggerBase.LogLevel.All;
  14. private string name;
  15. protected override FileInfo GetFileInfo()
  16. {
  17. var logsDir = new DirectoryInfo(Path.Combine("Logs",name));
  18. logsDir.Create();
  19. var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log"));
  20. return finfo;
  21. }
  22. public PluginLogFilePrinter(string name)
  23. {
  24. this.name = name;
  25. }
  26. public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message)
  27. {
  28. foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  29. fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper()));
  30. }
  31. }
  32. }