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 moreOr you could use the
master
branch of .net core.