diff --git a/src/ZeroLog.Tests/LogManagerTests.cs b/src/ZeroLog.Tests/LogManagerTests.cs index bf00090a..e2797ddb 100644 --- a/src/ZeroLog.Tests/LogManagerTests.cs +++ b/src/ZeroLog.Tests/LogManagerTests.cs @@ -189,7 +189,7 @@ public void should_not_throw_if_formatting_fails_when_using_format_string() signal.Wait(TimeSpan.FromMilliseconds(100)); var logMessage = _testAppender.LoggedMessages.Single(); - Check.That(logMessage).Equals("An error occured during formatting: \"A good format: {0:X4}, A bad format: {1:lol}, Another good format: {2}\", -23805, " + guid + ", True"); + Check.That(logMessage).Equals("An error occured during formatting: Unknown format specifier 'lol'. - Arguments: \"A good format: {0:X4}, A bad format: {1:lol}, Another good format: {2}\", -23805, " + guid + ", True"); } [Test] @@ -229,7 +229,7 @@ public unsafe void should_not_throw_if_formatting_fails_when_appending_formatted signal.Wait(TimeSpan.FromMilliseconds(100)); var logMessage = _testAppender.LoggedMessages.Single(); - Check.That(logMessage).Equals("An error occured during formatting: \"Hello\", False, 1, 'a', 2, 3, 4, 5, 6, 7, " + guid + ", 2017-02-24 16:51:51.000, 16:51:51, \"abc\", \"abc\", Friday"); + Check.That(logMessage).Equals("An error occured during formatting: Unknown format specifier 'meh, this is going to break formatting'. - Arguments: \"Hello\", False, 1, 'a', 2, 3, 4, 5, 6, 7, " + guid + ", 2017-02-24 16:51:51.000, 16:51:51, \"abc\", \"abc\", Friday"); } [Test] @@ -247,7 +247,7 @@ public void should_write_unformatted_unmanaged_struct_when_formatting_fails() signal.Wait(TimeSpan.FromMilliseconds(100)); var logMessage = _testAppender.LoggedMessages.Single(); - Check.That(logMessage).Equals("An error occured during formatting: Unmanaged(0x2a000000)"); + Check.That(logMessage).Equals("An error occured during formatting: Simulated failure - Arguments: Unmanaged(0x2a000000)"); } [Test] diff --git a/src/ZeroLog/LogManager.cs b/src/ZeroLog/LogManager.cs index b0a0d097..1749447b 100644 --- a/src/ZeroLog/LogManager.cs +++ b/src/ZeroLog/LogManager.cs @@ -275,9 +275,9 @@ private bool TryToProcessQueue(StringBuffer stringBuffer, byte[] destination) FormatLogMessage(stringBuffer, logEvent); bytesWritten = CopyStringBufferToByteArray(stringBuffer, destination); } - catch + catch (Exception ex) { - HandleFormattingError(stringBuffer, logEvent, destination, out bytesWritten); + HandleFormattingError(stringBuffer, logEvent, destination, ex, out bytesWritten); } WriteMessageLogToAppenders(destination, logEvent, bytesWritten); @@ -292,12 +292,14 @@ private bool TryToProcessQueue(StringBuffer stringBuffer, byte[] destination) } [MethodImpl(MethodImplOptions.NoInlining)] - private static void HandleFormattingError(StringBuffer stringBuffer, IInternalLogEvent logEvent, byte[] destination, out int bytesWritten) + private static void HandleFormattingError(StringBuffer stringBuffer, IInternalLogEvent logEvent, byte[] destination, Exception exception, out int bytesWritten) { try { stringBuffer.Clear(); stringBuffer.Append("An error occured during formatting: "); + stringBuffer.Append(exception.Message); + stringBuffer.Append(" - Arguments: "); logEvent.WriteToStringBufferUnformatted(stringBuffer); bytesWritten = CopyStringBufferToByteArray(stringBuffer, destination);