I have a use case where I need to log a full stack trace with all the details along with line number whenever any exception happens. I see there are two methods I can use here Exception.ToString()
vs Exception.Stacktrace
but I am confused which one I should use?
Also, I see a lot of StackOverflow posts and this article where people are talking about either using Ben.Demystifier
library or some other way.
catch (Exception ex)
{
Console.WriteLine(ex.Stacktrace);
Console.WriteLine(ex.ToString());
// using Ben.Demystifier library
Console.WriteLine(ex.ToStringDemystified());
}
I just wanted to understand what is the best and recommended way we can use to log a full stack trace of an exception?