很明显,为什么堆栈跟踪与微软的新的编程范式的影响。 我们现在有一个语义栈和物理夫妇的那些(我选择的词)。
我能看到却是一个例外的StackTrace
属性(在调试器)是物理的,然后连接起来:
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));
}
这给:
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
我的问题是:是否有一个(方便,标准)的方式将其转换为在语义意义上的适当的回溯,如:
CheckFooAndBar
Foo
Bar
当然也有可能是在堆栈等待并内嵌路径片段的混合物。
我试图寻找在堆栈,因为它与.NET 4.5,并与异步目标定位包SL5,但尚未与WinRT的。 输出是从.NET 4.5。
在SL5,这是我主要做,情况更成问题:你没有得到行号的堆栈跟踪在Silverlight(甚至提升的权限),这使得背景更重要的需要。