Get full stack trace with line numbers

.net, c#

Solution

I suspect you just want to call the overload taking a `bool`:

var stackTrace = new StackTrace(true);

From the documentation:

Parameters

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

Problem

Is it possible to get a full `StackTrace` object WITH line numbers at any given point in the code I found this: ``` var stackTrace = new StackTrace(); ``` That gives me the full stacktrace from where I am in execution. But it does not include line numbers. I also found this: ``` var stackTrace = new StackTrace(new StackFrame(1, true)); ``` That gives me the line numbers, but only for one frame of the StackTrace (not a full StackTrace). Is there a way to get both together? NOTE: I don't have an exception I am working with. I am just at a point in the code where I want to log the stack trace in a custom way. NOTE: I know about Environment.Properties.StackTrace. But that returns a string, not a `StackTrace` object.

Original source