diff --git a/Vostok.Logging.Formatting.Tests/Tokens/ExceptionToken_Tests.cs b/Vostok.Logging.Formatting.Tests/Tokens/ExceptionToken_Tests.cs index fda5541..9e6ff58 100644 --- a/Vostok.Logging.Formatting.Tests/Tokens/ExceptionToken_Tests.cs +++ b/Vostok.Logging.Formatting.Tests/Tokens/ExceptionToken_Tests.cs @@ -26,11 +26,11 @@ public void Should_not_render_anything_for_null_exception() } [Test] - public void Should_correctly_format_type_and_messages_for_exceptions_without_nested_exceptions() + public void Should_use_ToString_to_render_exception() { try { - throw new Exception("error1"); + throw new Exception("error1", new Exception("error2")); } catch (Exception error) { @@ -38,24 +38,12 @@ public void Should_correctly_format_type_and_messages_for_exceptions_without_nes Console.Out.WriteLine(result); - result.Should().StartWith("System.Exception: error1"); - } - } - - [Test] - public void Should_correctly_format_type_and_messages_for_exceptions_with_nested_exceptions() - { - try - { - throw new Exception("error1", new Exception("error2", new FormatException("error3"))); - } - catch (Exception error) - { - var result = Format(error); - - Console.Out.WriteLine(result); - - result.Should().StartWith("System.Exception: error1 ---> System.Exception: error2 ---> System.FormatException: error3"); + result.Should() + .Contain(error.ToString()) + .And.Contain(typeof(Exception).FullName) + .And.Contain("error1") + .And.Contain("error2") + .And.Contain(nameof(Should_use_ToString_to_render_exception)); } } diff --git a/Vostok.Logging.Formatting/Tokens/ExceptionToken.cs b/Vostok.Logging.Formatting/Tokens/ExceptionToken.cs index f397ca7..f18b26f 100644 --- a/Vostok.Logging.Formatting/Tokens/ExceptionToken.cs +++ b/Vostok.Logging.Formatting/Tokens/ExceptionToken.cs @@ -19,48 +19,7 @@ public override void Render(LogEvent @event, TextWriter writer, IFormatProvider if (@event.Exception == null) return; - RenderException(@event.Exception, writer, 0); - writer.WriteLine(); - } - - private static void RenderException(Exception error, TextWriter writer, int depth) - { - if (error == null) - return; - - if (depth > MaximumDepth) - { - writer.Write(""); - return; - } - - writer.Write(error.GetType().ToString()); - - var errorMessage = error.Message; - if (errorMessage != null) - { - writer.Write(": "); - writer.Write(errorMessage); - } - - var innerError = error.InnerException; - if (innerError != null) - { - writer.Write(" ---> "); - - RenderException(innerError, writer, depth + 1); - - writer.WriteLine(); - writer.Write(" "); - writer.Write("--- End of inner exception stack trace ---"); - } - - var stackTrace = error.StackTrace; - if (stackTrace != null) - { - writer.WriteLine(); - writer.Write(stackTrace); - } + writer.WriteLine(@event.Exception.ToString()); } } } \ No newline at end of file