Get full stack trace with line numbers

Is it possible to get the full line number of StackTrace WITH at any given point in the code

I found this:

 var stackTrace = new StackTrace(); 

This gives me the full stack I am executing from. But it does not include line numbers.

I also found this:

 var stackTrace = new StackTrace(new StackFrame(1, true)); 

This gives me line numbers, but for only one frame of StackTrace (not a complete StackTrace).

Is there a way to get both together?

NOTE. I have no exception I'm working with. I'm just at the code point where I want to register the stack trace in my own way.

NOTE. I know about Environment.Properties.StackTrace. But this returns a string, not a StackTrace object.

+6
source share
1 answer

I suspect you just want to reload with bool :

 var stackTrace = new StackTrace(true); 

From the documentation:

Options

fNeedFileInfo
Type: System.Boolean
true to capture the file name, line number, and column number; otherwise false .

+9
source

Source: https://habr.com/ru/post/983133/


All Articles