The developer dashboard is great for debugging web parts just by turning it on. There are also a few simple API calls you can use to add your own debugging information.

First turn it on

First make sure you have an elevated administrator prompt. You need to right click and say run as administrator to get this. There’s no error from STSADM if you aren’t elevated, it just wont perform the operation.

CD \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

STSADM –o setproperty –pn developer-dashboard –pv OnDemand

I remember it as developer dash dashboard so I get the –pn option right. The –pv option is case sensitive.

Once it’s turned on here are a few API calls you can use to output information.

Add a timed method scope in the left pane

This will add the text Some timed scope and it will list the number of milliseconds that the scoped code takes on the developer dashboard left pane.

using (SPMonitoredScope sc = new SPMonitoredScope(“Some timed scope”))
{
  // some code in here that you think may take time
}

Add a log, warning or assert message

This will add a message on the right side and at runtime you can click on the counter to see the detailed long message and a call stack. The call stack can add 2 or 3 Kb to your web page download so bear in mind this can significantly increase your time to page render if you have hundreds or thousands of these on a page and developer dashboard is turned on.

SPCriticalTraceCounter.AddDataToScope(uCounter, “Your category”, traceLevel, “Detailed long message”);

The traceLevel interprets the following to strings in the output:

1 Critical
4 Exception (Watson)
6 Assert
8 Warning
10 Unexpected
15 Monitorable