It is clear why stack tracing is dependent on Microsoft's new programming paradigm. Now we have a semantic stack and a couple of physical ones (my choice of words).
What I see is the exclusive property of StackTrace (and in the debugger) is physical, related:
private async Task CheckFooAndBar() { var log = LogManager.GetLogger("Test"); log.Info("CheckFooAndBar"); try { await Foo(); } catch (Exception ex) { log.Info("StackTrace of last exception: " + ex.StackTrace); } Console.ReadKey(); } private async Task Foo() { await Task.Factory.StartNew(() => Thread.Sleep(1000)); await Bar(); await Task.Factory.StartNew(() => Thread.Sleep(1000)); } private async Task Bar() { await Task.Factory.StartNew(() => Thread.Sleep(1000)); throw new Exception(); await Task.Factory.StartNew(() => Thread.Sleep(1000)); }
This gives:
StackTrace of last exception: at NLogAsyncExceptionTestCase.Program.<Bar>d__d.MoveNext() in c:\Users\Jens\Documents\Visual Studio 2012\Projects\NLogAsyncExceptionTestCase\NLogAsyncExceptionTestCase.Console\Program.cs:line 53 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at NLogAsyncExceptionTestCase.Program.<Foo>d__8.MoveNext() in c:\Users\Jens\Documents\Visual Studio 2012\Projects\NLogAsyncExceptionTestCase\NLogAsyncExceptionTestCase.Console\Program.cs:line 44 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at NLogAsyncExceptionTestCase.Program.<CheckFooAndBar>d__0.MoveNext() in c:\Users\Jens\Documents\Visual Studio 2012\Projects\NLogAsyncExceptionTestCase\NLogAsyncExceptionTestCase.Console\Program.cs:line 30
My question is: is there a (convenient, standard) way to convert this to the correct return line in the semantic sense, for example:
CheckFooAndBar Foo Bar
Of course, there may be a mixture of expectations and inline fragments of the path on the stack.
I tried to look at the stack, as well as on .NET 4.5 and SL5, with the async targeting package, but not WinRT yet. Exit from .NET 4.5.
In SL5, which I mostly do, the situation is more problematic: you do not get the line numbers on the stacks in Silverlight (even with elevated privileges), which makes the need for context more important.
stack-trace c # logging async-await visual-studio-debugging
John Dec 14 '12 at 18:37 2012-12-14 18:37
source share