.NET Core中当前位置的堆栈跟踪 [英] stack trace from the current location in .NET Core

查看:321
本文介绍了.NET Core中当前位置的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从当前位置构造堆栈跟踪?



在.NET 4.5中,此解决方案起作用:

  System.Diagnostics.StackTrace stackTrace =新的System.Diagnostics.StackTrace(true); 
for(int i = 0; i< stackTrace.FrameCount; ++ i)
{
System.Diagnostics.StackFrame frame = stackTrace.GetFrame(i);
MethodBase调用者方法= frame.GetMethod();
...
}

.NET Core中的解决方案是什么?
构造函数 public StackTrace(bool fNeedFileInfo)不再存在。

解决方案

更新 .NET Standard 2.0已发布,并且构造函数已如期在其中。






目前似乎这种类型不可用。在此帖子中,提到将其添加到.net standard 2.0中。 / p>

您可以使用 System.Diagnostics.StackTrace nuget程序包,它支持.net core 5.0,.net standart 1.3及更高版本



或者您可以使用 .net核心的 master 分支。


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.

解决方案

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.

这篇关于.NET Core中当前位置的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆