using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DiscordRPC.Logging { /// /// Logs the outputs to a file /// public class FileLogger : ILogger { /// /// The level of logging to apply to this logger. /// public LogLevel Level { get; set; } /// /// Should the output be coloured? /// public string File { get; set; } private object filelock; /// /// Creates a new instance of the file logger /// /// The path of the log file. public FileLogger(string path) : this(path, LogLevel.Info) { } /// /// Creates a new instance of the file logger /// /// The path of the log file. /// The level to assign to the logger. public FileLogger(string path, LogLevel level) { Level = level; File = path; filelock = new object(); } /// /// Informative log messages /// /// /// public void Trace(string message, params object[] args) { if (Level > LogLevel.Trace) return; lock (filelock) System.IO.File.AppendAllText(File, "\r\nTRCE: " + (args.Length > 0 ? string.Format(message, args) : message)); } /// /// Informative log messages /// /// /// public void Info(string message, params object[] args) { if (Level > LogLevel.Info) return; lock(filelock) System.IO.File.AppendAllText(File, "\r\nINFO: " + (args.Length > 0 ? string.Format(message, args) : message)); } /// /// Warning log messages /// /// /// public void Warning(string message, params object[] args) { if (Level > LogLevel.Warning) return; lock (filelock) System.IO.File.AppendAllText(File, "\r\nWARN: " + (args.Length > 0 ? string.Format(message, args) : message)); } /// /// Error log messsages /// /// /// public void Error(string message, params object[] args) { if (Level > LogLevel.Error) return; lock (filelock) System.IO.File.AppendAllText(File, "\r\nERR : " + (args.Length > 0 ? string.Format(message, args) : message)); } } }