Skip to content

Inner exceptions #16

@enkelmedia

Description

@enkelmedia

Thanks for a great little utility!

I'm missing the inner exceptions in the logging, sometimes they might say more about the error than the actual exception.

I've added this little code in a local copy - Is this something that you would like to see as PR? Maybe we could use a setting or something if we don't want to include it by default? "IncludeInnerException"

    `if (exception!= null && exception.InnerException != null)
            {
                theAttachment.Fields.Insert(0, new Field("Inner Exception Type", Value: exception.InnerException.GetType().Name, Short: true));
                if (AddExceptionTraceField && !string.IsNullOrWhiteSpace(exception.InnerException.StackTrace))
                {
                    var parts = exception.InnerException.StackTrace.SplitOn(1990).ToArray(); // Split call stack into consecutive fields of ~2k characters
                    for (int idx = parts.Length - 1; idx >= 0; idx--)
                    {
                        var name = "Inner exception Trace" + (idx > 0 ? string.Format(" {0}", idx + 1) : null);
                        theAttachment.Fields.Insert(0, new Field(name, Value: "```" + parts[idx].Replace("```", "'''") + "```"));
                    }
                }

                theAttachment.Fields.Insert(0, new Field("Inner Exception Message", Value: exception.InnerException.Message));
            }`

Let me know what you think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions