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.

30 lines
1.1 KiB

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