Did you know… You can use Tracepoints to log “printf” or “console.writeline” info without editing your code? – #237

his was tip #15 in my TechEd 2008 VS IDE Tips and Tricks talk.

This is a new feature for VS2008.

On a given line of code where you want to log the value of a variable, you could do the old fashion way of doing a Console.Writeline() or a PrintF().  But in VS 2008, there’s a new feature called tracepoints.

Just right-click, select breakpoints, but instead of Insert Breakpoint, select Insert Tracepoint.

Insert Tracepoints from Context Menu

This will bring up the Tracepoint dialog, where VS gives you some helpful defaults.  But for this example, the really helpful default is in the descriptive text for logging the contents of a variable.

Tracepoints dialog

You’ll notice that the editor shows a diamond instead of a circle.

Tracepoints indicated by a diamond

And the tracepoints are logged in the Output Window’s Debug Pane

Debug Window Output Pane logs tracepoints

Technorati Tags: VS2008Tip

Comments (9)

  1. John Garland says:

    Thanks for the tip Sara.  One nit, however…I am not sure this is actually a "new feature" in VS2008 – it is just more accessible in VS2008 than it was in VS2005.  In VS2005, simply drop a breakpoint (F9) and then right click on the breakpoint icon in the margin or on the line where the breakpoint itself resides.  From the breakpoint popup select "When Hit" and check "Print Message".  If "Continue Execution" is checked (which it is by default as soon as you select "Print Message"), you have a Tracepoint.

  2. Thanks soooooo much for uncovering these TracePoints. I would never have found them alone! (Now, WHO uses the context menu to set a breakpoint?)

    Wait, it works for Compact Framework debugging on Windows Mobile devices as well.

    A very nice birthday present you came with 😉

  3. Alex Black says:

    Great tip Sara, thanks. I hadn’t heard about that, I will have to try it out.

    – Alex

  4. Bryant says:

    Great feature, though this debuted in VS2005, not 2008…

  5. MarcT says:

    Tracepoints could use a weeks of tips themselves. Stuff that’s really hidden like all the special words ($FUNCTION, $CALLER, etc) – there are some that are not listed in the dialog (i.e. $TICK for timing info). Also, formatting – you can write {foo,x} to see foo in hex, for example.

    My favorite secret unsupported feature of tracepoints is that the default text for a new tracepoint ($THREAD: $FUNCTION or something) can be changed via the registry.

    Feature request: Save my currently active tracepoints to a file so I can load them quickly next time this same function breaks.

  6. Want to trace some run-time data to the output window while debugging without changing and recompiling

  7. Guru Stop says:

    · Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask · Functional Programming in

  8. My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. I’ve been on vacation in Alaska for 10 days so this is an extra long list of links. Sara Ford: Tip of the Day #236 covers the file