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.

36 lines
1.1 KiB

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