chi*_*tom 11 c# regex parsing stack-trace
C#堆栈跟踪采用以下形式:
at Foo.Core.Test.FinalMethod(Doh doh) in C:\Projects\src\Core.Tests\Test.cs:line 21
at Foo.Core.Test.AnotherMethod(Bar bar)
at Foo.Core.Test.AMethod() in C:\Projects\src\Core.Tests\Test.cs:line 6
at Foo.Core.Test.<>c__DisplayClass7.<SomeAnonDelegate>b__6(Object _) in C:\Projects\src\Core.Tests\Test.cs:line 35
Run Code Online (Sandbox Code Playgroud)
如何从每一行检索命名空间,类,方法,文件和行号?
会欣赏一些想法和意见.
Aus*_*nen 14
如果你从得到这个堆栈跟踪,那么你就可以遍历StackFrames通过的getFrame和调用GetMethod,用GetFileName和GetFileLineNumber.可以从方法中检索命名空间和类.
编辑
响应第一条注释(不幸的是我们从Exception.StackTrace获取了跟踪),您可以调用StackTrace(Exception)构造函数.
编辑
我应该链接到这个构造函数 - StackTrace(Exception,bool).