7

I know it was possible to use:

System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();

but that seems to not work anymore, as it needs an Exception-Object.

Jens Marchewka
  • 1,362
  • 1
  • 13
  • 22

3 Answers3

2

Try Environment.StackTrace. Just remember to be careful with what your logic afterwards is as stacks can change in unpredictable ways. Some discussion here: https://github.com/dotnet/corefx/issues/1420

1

Check out this discussion on .NET Core's github: Where have StackTrace and StackFrame gone?.

This class isn't there in .NET Core, but there's an open task to implement it: Implement System.Diagnostics.StackTrace/StackFrame - just no one actively working on it yet.

Filip Skakun
  • 31,495
  • 6
  • 72
  • 99
1

As a workaround until .Net Core 2.0 will be available you can parse Environment.StackTrace string as suggested in answeres to How to split a stacktrace line into namespace, class, method file and line number? -using RegEx or StackTraceParser

Michael Freidgeim
  • 23,917
  • 16
  • 136
  • 163