Saint
Saint

Reputation: 5469

Print the callstack of debugger (method names) to the file or console in VS2010

Is it possible to print route of debugger into the file or console? I think about e.g names of methods where it actually enter. In other words what I see hit F11, F11, F11 ... I want to have in file. How can I do this?

Upvotes: 4

Views: 5395

Answers (1)

Omer Raviv
Omer Raviv

Reputation: 11827

Yes, you could add the following to your code, or just run it from the Immediate Window when you are in Break mode:

System.IO.File.WriteAllText("myTrace.txt", new System.Diagnostics.StackTrace(true).ToString())

Alternatively, you could add tracepoints to your code and use the $CALLSTACK psuedo-variable.

UPDATE: I'm a co-creator of a Visual Studio extensions called OzCode, and I added a feature that makes it much easier to do what OP requested. The feature is essentially "Tracepoints on Steroids".

To do this, use the QuickAction "Create Tracepoint Here"

Create Tracepoint

Then, enter some text and/or expressions you want to appear next to the callstack, and make sure "Save Stack" is checked:

Save Stack

Then, every time you hit your tracepoint, a new line will be added to the Tracepoint Viewer. You can view the full callstack by clicking the arrow next to it:

Export

Now, just hit the "Export" button in the top-right corner to save all your callstacks to a file.

Upvotes: 6

Related Questions