using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using IPA.Logging; namespace IPA.Logging.Printers { /// /// A printer for all messages to a unified log location. /// public class GlobalLogFilePrinter : GZFilePrinter { /// /// Provides a filter for this specific printer. /// public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All; /// /// Prints an entry to the associated file. /// /// the of the message /// the the message was recorded at /// the name of the log that sent the message /// the message to print public override void Print(Logger.Level level, DateTime time, string logName, string message) { foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) fileWriter.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper())); } /// /// Gets the for the target file. /// /// protected override FileInfo GetFileInfo() { var logsDir = new DirectoryInfo("Logs"); logsDir.Create(); var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log")); return finfo; } } }