using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.Logging { /// /// Represents a base class for log items. /// public abstract class LogItemBase { private static String base_path; /// /// Gets or sets the assembly. /// public String CallerAssembly { get; set; } /// /// Gets or sets the caller method adding the exception. /// public String CallerMethodName { get; set; } /// /// Gets or sets the caller file. /// public String CallerFile { get; set; } /// /// Gets the relative caller file. /// public String RelativeCallerFile { get { return GetRelativeCallerFilePath(); } } /// /// Gets or sets the caller line number. /// public int CallerLineNumber { get; set; } /// /// Gets or sets the DateTime for the log. /// public DateTime TimeStamp { get; set; } /// /// Gets or sets the log category. /// public LogCategory Category { get; set; } /// /// Gets the log message. /// public abstract String Message { get; set; } /// /// Returns a formatted string of the log item. /// public abstract override String ToString(); /// /// Gets the relative caller file path. /// /// protected String GetRelativeCallerFilePath() { if (base_path == null) { int index = CallerFile.IndexOf("Visual_Studio") + "Visual_Studio".Length + 1; String relative = CallerFile.Substring(index, CallerFile.Length - index); base_path = CallerFile.Replace(relative, ""); } if (Path.IsPathRooted(CallerFile)) { return CallerFile.Remove(0, base_path.Length); } else { return CallerFile; } } } }