Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Dlls/StackifyLib.ELMAH/StackifyLib.ELMAH.dll
Binary file not shown.
Binary file modified Dlls/StackifyLib.log4net.Sitecore/StackifyLib.log4net.dll
Binary file not shown.
Binary file modified Dlls/StackifyLib.log4net.v1_2_10/StackifyLib.log4net.dll
Binary file not shown.
Binary file modified Dlls/StackifyLib.log4net/StackifyLib.log4net.dll
Binary file not shown.
Binary file modified Dlls/StackifyLib.nLog/StackifyLib.nLog.dll
Binary file not shown.
Binary file modified Dlls/StackifyLib/StackifyLib.dll
Binary file not shown.
55 changes: 46 additions & 9 deletions Src/StackifyLib.log4net.Sitecore/StackifyAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -283,7 +304,23 @@ internal LogMsg Translate(LoggingEvent loggingEvent)
return msg;
}

private Dictionary<string, object> 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<string, object> GetDiagnosticContextProperties()
{
if (!_HasContextKeys)
{
Expand Down