LogPrefixer.cs
1 namespace Logging 2 { 3 public class LogPrefixer : ILog 4 { 5 private readonly ILog backingLog; 6 7 public LogPrefixer(ILog backingLog) 8 { 9 this.backingLog = backingLog; 10 } 11 12 public LogPrefixer(ILog backingLog, string prefix) 13 { 14 this.backingLog = backingLog; 15 Prefix = prefix; 16 } 17 18 public string Prefix { get; set; } = string.Empty; 19 20 public LogFile CreateSubfile(string addName, string ext = "log") 21 { 22 return backingLog.CreateSubfile(addName, ext); 23 } 24 25 public void Debug(string message = "", int skipFrames = 0) 26 { 27 backingLog.Debug(GetPrefix() + message, skipFrames + 1); 28 } 29 30 public void Error(string message) 31 { 32 backingLog.Error(GetPrefix() + message); 33 } 34 35 public void Log(string message) 36 { 37 backingLog.Log(GetPrefix() + message); 38 } 39 40 public void AddStringReplace(string from, string to) 41 { 42 backingLog.AddStringReplace(from, to); 43 } 44 45 public void Raw(string message) 46 { 47 backingLog.Raw(message); 48 } 49 50 public string GetFullName() 51 { 52 return backingLog.GetFullName(); 53 } 54 55 protected virtual string GetPrefix() 56 { 57 return Prefix; 58 } 59 } 60 }