Reputation:
I have C# code that's giving an exception. I have the code within a try - catch and I can see the exception but I am having a problem viewing it in VS2012. Is there a way I can send a stack trace to the console so I can look without having to right click on properties of the exception?
Even better does anyone have any code they use to log out more detailed information to the console?
Upvotes: 2
Views: 143
Reputation: 2574
From any piece of code you can access the stack by creating a stackframe object. Lots of information in there and you don't need an exception to access it.
EG.
var callingMethod = new StackFrame(1).GetMethod().Name;
returns the calling method name.
If you have an exception as Joe Daley suggested use
Console.WriteLine(ex);
to print it out.
Upvotes: 3