Is there a C# equivalent method to Java\'s Exception.printStackTrace()
or do I have to write something myself, working my way through the InnerExceptions?
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx
Console.WriteLine(myException.StackTrace);
Also look at Log4Net... its a port of Log4J to .NET.
I would like to add: If you want to print the stack outside of an exception, you can use:
Console.WriteLine(System.Environment.StackTrace);
Is there no C# Logging API that can take an Exception as an argument and handle everything for you, like Java's Log4J does?
I.e., use Log4NET.
Since @ryan-cook answer didn't work for me, if you want to print the stack trace without having an exception, you can use:
System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
Console.WriteLine(stackTrace)
Unfortunately, this can't be done in a PCL or in a .NETStandard Library
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}