void AddMessage(string category, StackFrameInfo stackFrame, string message) { var result = new StringBuilder(); result.Append($"[{category}"); if (!stackFrame.IsEmpty) { var fileName = stackFrame.FileName; if (fileName.StartsWith(currentDirectory)) fileName = fileName.Substring(currentDirectory.Length + 1); result.Append($" @ {fileName}:{stackFrame.LineNumber}"); } result.Append($"] => {message}"); Messages.Add(result.ToString()); }
void AddMessage(string category, StackFrameInfo stackFrame, string message) { var result = new StringBuilder(); result.AppendFormat("[{0}", category); if (!stackFrame.IsEmpty) { var fileName = stackFrame.FileName; if (fileName.StartsWith(currentDirectory)) fileName = fileName.Substring(currentDirectory.Length + 1); result.AppendFormat(" @ {0}:{1}", fileName, stackFrame.LineNumber); } result.AppendFormat("] => {0}", message); Messages.Add(result.ToString()); }
public void LogImportantMessage(StackFrameInfo stackFrame, string message) { AddMessage("Imp", stackFrame, message); }
public void LogMessage(StackFrameInfo stackFrame, string message) { AddMessage("---", stackFrame, message); }
/// <summary> /// Lots test output to the logger. /// </summary> protected virtual void LogOutput(StackFrameInfo frameInfo, string output) { if (string.IsNullOrEmpty(output)) return; // ITestOutputHelper terminates everything with NewLine, but we really don't need that // extra blank line in our output. if (output.EndsWith(Environment.NewLine, StringComparison.Ordinal)) output = output.Substring(0, output.Length - Environment.NewLine.Length); Logger.LogMessage(frameInfo, " Output:"); foreach (var line in output.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) Logger.LogImportantMessage(frameInfo, $" {line}"); }
public void LogError(StackFrameInfo stackFrame, string message) { AddMessage("Err", stackFrame, message); }
/// <inheritdoc/> public void LogWarning(StackFrameInfo stackFrame, string message) { using (SetColor(ConsoleColor.Yellow)) lock (LockObject) Console.WriteLine(message); }
/// <summary> /// Logs a stack trace to the logger. /// </summary> protected virtual void LogStackTrace(StackFrameInfo frameInfo, string stackTrace) { if (string.IsNullOrEmpty(stackTrace)) return; Logger.LogMessage(frameInfo, " Stack Trace:"); foreach (var stackFrame in stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) Logger.LogImportantMessage(frameInfo, $" {StackFrameTransformer.TransformFrame(stackFrame, defaultDirectory)}"); }
/// <summary> /// Logs a high-priority formatted message with stack frame. /// </summary> /// <param name="logger">The logger</param> /// <param name="stackFrame">The stack frame information</param> /// <param name="messageFormat">The format of the message to be logged</param> /// <param name="args">The format arguments</param> public static void LogImportantMessage(this IRunnerLogger logger, StackFrameInfo stackFrame, string messageFormat, params object[] args) { logger.LogImportantMessage(stackFrame, string.Format(messageFormat, args)); }
/// <inheritdoc/> public void LogMessage(StackFrameInfo stackFrame, string message) { using (SetColor(ConsoleColor.DarkGray)) lock (LockObject) Console.WriteLine(message); }
public void LogWarning(StackFrameInfo stackFrame, string message) { }
public void LogWarning(StackFrameInfo stackFrame, string message) { AddMessage("Wrn", stackFrame, message); }
public void LogMessage(StackFrameInfo stackFrame, string message) { }
public void LogImportantMessage(StackFrameInfo stackFrame, string message) { }
public void LogError(StackFrameInfo stackFrame, string message) { }
/// <inheritdoc/> public void LogImportantMessage(StackFrameInfo stackFrame, string message) { using (SetColor(ConsoleColor.Gray)) lock (LockObject) Console.WriteLine(message); }
/// <inheritdoc/> public void LogError(StackFrameInfo stackFrame, string message) { using (SetColor(ConsoleColor.Red)) lock (LockObject) Console.Error.WriteLine(message); }