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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
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.
Also look at Log4Net... its a port of Log4J to .NET.
As Drew says, just converting the exception a string does this. For instance, this program:
Produces this output:
Since @ryan-cook answer didn't work for me, if you want to print the stack trace without having an exception, you can use:
Unfortunately, this can't be done in a PCL or in a .NETStandard Library
Try this:
From http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx:
Note that in the above code the call to
ToString
isn't required as there's an overload that takesSystem.Object
and callsToString
directly.http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx
Console.WriteLine(myException.StackTrace);