/// <summary> /// Logs an error message to the logger. /// </summary> /// <param name="failureType">The type of the failure</param> /// <param name="failureInfo">The failure information</param> protected void LogError(string failureType, IFailureInformation failureInfo) { var frameInfo = StackFrameInfo.FromFailure(failureInfo); lock (Logger.LockObject) { Logger.LogError(frameInfo, $" [{failureType}] {Escape(failureInfo.ExceptionTypes.FirstOrDefault() ?? "(Unknown Exception Type)")}"); foreach (var messageLine in ExceptionUtility.CombineMessages(failureInfo).Split(new[] { Environment.NewLine }, StringSplitOptions.None)) Logger.LogImportantMessage(frameInfo, $" {messageLine}"); LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(failureInfo)); } }
/// <summary> /// Called when <see cref="ITestFailed"/> is raised. /// </summary> /// <param name="args">An object that contains the event data.</param> protected virtual void HandleTestFailed(MessageHandlerArgs<ITestFailed> args) { var testFailed = args.Message; var frameInfo = StackFrameInfo.FromFailure(testFailed); lock (Logger.LockObject) { Logger.LogError(frameInfo, $" {Escape(testFailed.Test.DisplayName)} [FAIL]"); foreach (var messageLine in ExceptionUtility.CombineMessages(testFailed).Split(new[] { Environment.NewLine }, StringSplitOptions.None)) Logger.LogImportantMessage(frameInfo, $" {messageLine}"); LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(testFailed)); LogOutput(frameInfo, testFailed.Output); } }
/// <inheritdoc/> protected override bool Visit(ITestFailed testFailed) { var frameInfo = StackFrameInfo.FromFailure(testFailed); lock (Logger.LockObject) { Logger.LogError(frameInfo, $" {Escape(testFailed.Test.DisplayName)} [FAIL]"); foreach (var messageLine in ExceptionUtility.CombineMessages(testFailed).Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { Logger.LogImportantMessage(frameInfo, $" {messageLine}"); } LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(testFailed)); LogOutput(frameInfo, testFailed.Output); } return(base.Visit(testFailed)); }