Skip to content

Commit 17aa75a

Browse files
authored
Merge pull request #1402 from rappen/master
Logging error with message and all inner exceptions, and full stack t…
2 parents b74aefb + 0a03fbb commit 17aa75a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

XrmToolBox.Extensibility/Forms/ErrorDetail.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public partial class ErrorDetail : Form
1818

1919
public ErrorDetail(PluginControlBase owner, Exception exception, string heading, string extrainfo, bool allownewissue)
2020
{
21+
if (exception == null)
22+
{ // Just in case...
23+
return;
24+
}
25+
if (owner != null)
26+
{ // Log error with details and stack trace
27+
owner.LogError(exception.ExceptionDetails() + "\r\n" + exception.StackTrace);
28+
}
2129
this.owner = owner;
2230
this.exception = exception?.InnerException ?? exception;
2331
this.extrainfo = extrainfo;
@@ -169,4 +177,10 @@ private void panDetails_VisibleChanged(object sender, EventArgs e)
169177
Height = panButton.Height + panInfo.Height + (panDetails.Visible ? panDetails.Height : 0) + 50;
170178
}
171179
}
180+
181+
public static class ExceptionExtensions
182+
{
183+
public static string ExceptionDetails(this Exception ex, int level = 0) => ex == null ? string.Empty :
184+
$"{new string(' ', level * 2)}{ex.Message}{Environment.NewLine}{ex.InnerException.ExceptionDetails(level + 1)}".Trim();
185+
}
172186
}

0 commit comments

Comments
 (0)