diff --git a/Dlls/StackifyLib.ELMAH/StackifyLib.ELMAH.dll b/Dlls/StackifyLib.ELMAH/StackifyLib.ELMAH.dll index 3103b0e..74b17a4 100644 Binary files a/Dlls/StackifyLib.ELMAH/StackifyLib.ELMAH.dll and b/Dlls/StackifyLib.ELMAH/StackifyLib.ELMAH.dll differ diff --git a/Dlls/StackifyLib.log4net.Sitecore/StackifyLib.log4net.dll b/Dlls/StackifyLib.log4net.Sitecore/StackifyLib.log4net.dll index 2c2413a..b233e49 100644 Binary files a/Dlls/StackifyLib.log4net.Sitecore/StackifyLib.log4net.dll and b/Dlls/StackifyLib.log4net.Sitecore/StackifyLib.log4net.dll differ diff --git a/Dlls/StackifyLib.log4net.v1_2_10/StackifyLib.log4net.dll b/Dlls/StackifyLib.log4net.v1_2_10/StackifyLib.log4net.dll index e8b5230..b68afae 100644 Binary files a/Dlls/StackifyLib.log4net.v1_2_10/StackifyLib.log4net.dll and b/Dlls/StackifyLib.log4net.v1_2_10/StackifyLib.log4net.dll differ diff --git a/Dlls/StackifyLib.log4net/StackifyLib.log4net.dll b/Dlls/StackifyLib.log4net/StackifyLib.log4net.dll index d574502..641d4c0 100644 Binary files a/Dlls/StackifyLib.log4net/StackifyLib.log4net.dll and b/Dlls/StackifyLib.log4net/StackifyLib.log4net.dll differ diff --git a/Dlls/StackifyLib.nLog/StackifyLib.nLog.dll b/Dlls/StackifyLib.nLog/StackifyLib.nLog.dll index 40be315..cf3ba51 100644 Binary files a/Dlls/StackifyLib.nLog/StackifyLib.nLog.dll and b/Dlls/StackifyLib.nLog/StackifyLib.nLog.dll differ diff --git a/Dlls/StackifyLib/StackifyLib.dll b/Dlls/StackifyLib/StackifyLib.dll index f182f0a..76975db 100644 Binary files a/Dlls/StackifyLib/StackifyLib.dll and b/Dlls/StackifyLib/StackifyLib.dll differ diff --git a/Src/StackifyLib.log4net.Sitecore/StackifyAppender.cs b/Src/StackifyLib.log4net.Sitecore/StackifyAppender.cs index 572a537..a8827a9 100644 --- a/Src/StackifyLib.log4net.Sitecore/StackifyAppender.cs +++ b/Src/StackifyLib.log4net.Sitecore/StackifyAppender.cs @@ -176,7 +176,6 @@ internal LogMsg Translate(LoggingEvent loggingEvent) StackifyError error = null; object messageObject = null; string errorAdditionalMessage = null; - if (loggingEvent.MessageObject != null && loggingEvent.MessageObject is StackifyError) { //Message Object was an exception @@ -211,13 +210,35 @@ internal LogMsg Translate(LoggingEvent loggingEvent) // messageObject = loggingEvent.MessageObject; //} else - { - messageObject = loggingEvent.MessageObject; - } - - - //messageObject is not an object we need to serialize. - if (messageObject == null || messageObject is string || messageObject.GetType().FullName == "log4net.Util.SystemStringFormat") + { + // we try to retrieve the thrown exception but wait to do this check until this last condition + // block since we need to use reflection which is an expensive operation + Exception thrownException = GetThrownException(loggingEvent); + + if (thrownException == null) + { + // the thrown exception does not exist, so we use the basic information provided in the message object + messageObject = loggingEvent.MessageObject; + } + else + { + if (thrownException is StackifyError) + { + error = thrownException as StackifyError; + } + else + { + error = StackifyError.New(thrownException); + } + + errorAdditionalMessage = loggingEvent.RenderedMessage; + messageObject = loggingEvent.MessageObject; + } + } + + + //messageObject is not an object we need to serialize. + if (messageObject == null || messageObject is string || messageObject.GetType().FullName == "log4net.Util.SystemStringFormat") { //passing null to the serialize object since we can't serialize the logged object. We only need to get potential diags. msg.data = StackifyLib.Utils.HelperFunctions.SerializeDebugData(null, false, diags); @@ -283,7 +304,23 @@ internal LogMsg Translate(LoggingEvent loggingEvent) return msg; } - private Dictionary GetDiagnosticContextProperties() + private Exception GetThrownException(LoggingEvent loggingEvent) + { + // Since Sitecore's implementation does not expose the ExceptionObject, we need to use reflection to get access + // to it, as per Matt Watson from Stackify. We know they store this Exception in a field with the name m_thrownException + // so we retrieve the private field based on its name. + Exception thrownException = null; + Type loggingEventType = loggingEvent.GetType(); + var thrownExceptionFieldInfo = loggingEventType.GetField("m_thrownException", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); + if (thrownExceptionFieldInfo != null) + { + thrownException = thrownExceptionFieldInfo.GetValue(loggingEvent) as Exception; + } + + return thrownException; + } + + private Dictionary GetDiagnosticContextProperties() { if (!_HasContextKeys) {