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.

42 lines
1.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. using IPA.Utilities;
  2. using System;
  3. using System.IO;
  4. namespace IPA.Logging.Printers
  5. {
  6. /// <summary>
  7. /// A printer for all messages to a unified log location.
  8. /// </summary>
  9. public class GlobalLogFilePrinter : GZFilePrinter
  10. {
  11. /// <summary>
  12. /// Provides a filter for this specific printer.
  13. /// </summary>
  14. /// <value>the filter level for this printer</value>
  15. public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
  16. /// <summary>
  17. /// Prints an entry to the associated file.
  18. /// </summary>
  19. /// <param name="level">the <see cref="Logger.Level"/> of the message</param>
  20. /// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
  21. /// <param name="logName">the name of the log that sent the message</param>
  22. /// <param name="message">the message to print</param>
  23. public override void Print(Logger.Level level, DateTime time, string logName, string message)
  24. {
  25. foreach (var line in removeControlCodes.Replace(message, "").Split(new[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  26. FileWriter.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper());
  27. }
  28. /// <summary>
  29. /// Gets the <see cref="FileInfo"/> for the target file.
  30. /// </summary>
  31. /// <returns>the target file to write to</returns>
  32. protected override FileInfo GetFileInfo()
  33. {
  34. var logsDir = new DirectoryInfo("Logs");
  35. logsDir.Create();
  36. var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{Utils.CurrentTime():yyyy.MM.dd.HH.mm.ss}.log"));
  37. return finfo;
  38. }
  39. }
  40. }