.NET Core 中当前位置的堆栈跟踪 [英] stack trace from the current location in .NET Core
问题描述
如何从当前位置构建堆栈跟踪?
How can I constructs a stack trace from the current location?
在 .NET 4.5 中使用此解决方案:
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();
...
}
但是 .NET Core 中的解决方案是什么?构造函数 public StackTrace(bool fNeedFileInfo)
不再存在.
But what is the solution in .NET Core?
The constructor public StackTrace(bool fNeedFileInfo)
does not exists anymore.
推荐答案
UPDATE .NET Standard 2.0 已经发布,构造函数已经按照承诺在里面了.
UPDATE .NET Standard 2.0 has been released and the constructor is in there as promised.
目前似乎没有这种类型.在这篇文章中提到它将被添加到 .net 标准 2.0.
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.
您可以使用 System.Diagnostics.StackTrace
nuget 包,支持 .net core 5.0、.net standart 1.3 和更多
You could use the System.Diagnostics.StackTrace
nuget package which supports .net core 5.0, .net standart 1.3 and more
或者你可以使用 master
.net core 的分支.
Or you could use the master
branch of .net core.
这篇关于.NET Core 中当前位置的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!