stack trace from the current location in .NET Core

↘锁芯ラ 提交于 2019-12-11 07:02:36

问题


How can I constructs a stack trace from the current location?

In .NET 4.5 works this solution:

System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true);
for (int i = 0; i < stackTrace.FrameCount; ++i)
{
    System.Diagnostics.StackFrame frame = stackTrace.GetFrame(i);
    MethodBase callerMethod = frame.GetMethod();
    ...
}

But what is the solution in .NET Core? The constructor public StackTrace(bool fNeedFileInfo) does not exists anymore.


回答1:


UPDATE .NET Standard 2.0 has been released and the constructor is in there as promised.


It seems like this type is at the moment not available. In this post it is mentioned that it will be added to .net standard 2.0.

You could use the System.Diagnostics.StackTrace nuget package which supports .net core 5.0, .net standart 1.3 and more

Or you could use the master branch of .net core.



来源:https://stackoverflow.com/questions/45038688/stack-trace-from-the-current-location-in-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!