-
Notifications
You must be signed in to change notification settings - Fork 147
Adding inner exception message to SelfLog #415
-
Hi, it would be super userful if the the exception message of an inner exception could be added to the self log in the batch writing.
I had a scenario where it took me quite a while to figure out that I was really dealing with a binding problem with System.Runtime.InteropServices.RuntimeInformation rather than an error in the SQL-handling which the SelfLog displayed from the top level exception message.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 2 replies
-
Hi @CarlJohan79!
Thanks for bringing this up. Sounds like a good idea. There are only a few spots (four if i counted correctly) in the code where exceptions are logged using SelfLog. A general helper method for this checking if it's an aggregate/nested exception to log more details in this case would be a good improvement.
Can you provide a small sample program to help us testing such an implementation?
Regards,
Christian
Beta Was this translation helpful? Give feedback.
All reactions
-
Cool, could you perhaps implement something like this:
public static class ExceptionExtensions { public static string ToMessageAndCompleteStacktrace(this Exception exception) { Exception e = exception; StringBuilder s = new StringBuilder(); while (e != null) { s.AppendLine("Exception type: " + e.GetType().FullName); s.AppendLine("Message : " + e.Message); s.AppendLine(); e = e.InnerException; } return s.ToString(); } }
And then use it like this:
SelfLog.WriteLine(ex.ToMessageAndCompleteStacktrace());
Above copied from this thread: https://stackoverflow.com/questions/18489387/what-is-the-best-practice-for-capturing-all-inner-exception-details
Beta Was this translation helpful? Give feedback.
All reactions
-
Looks good. Can you send a PR. I'll be happy to review it.
Beta Was this translation helpful? Give feedback.
All reactions
-
We have now merged a PR which fixes this issue. Please try it out with the latest dev version on nuget.org.
Beta Was this translation helpful? Give feedback.
All reactions
-
Cool, thanx, I will try it out as soon as possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1