Easy Debugging With Developer Dashboard In SharePoint

As we know writing code for SharePoint sites is not difficult whether we are writing server side or client-side code for customizing features. The main point where everyone gets struck is troubleshooting or handling errors related to code. Also, error logging for SharePoint sites is done to both ULS and Windows Event Logs and finding or reading logs sometimes is really a mess. As, reading ULS (SharePoint Unified Logging Service) is not easy for everyone to get through. So, a new feature was introduced in SharePoint 2010 named Developer Dashboard.
 

What is developer dashboard?

 
Developer Dashboard is introduced as a new feature in SharePoint 2010. It’s a user interface which reflects useful diagnostic information. Developer dashboards are helpful to not only developers in debugging but also to administrators in handling issues related to farm.
 
Developer Dashboard gives the information about performance of controls used of a SharePoint page. Also, it tells about execution time taken by each control, log correlation ID, critical events, database queries with their handling time, service calls, SPRequests allocation whether used nominal or not and webparts event offsets (time taken in loading and rendering of webparts). This is a very helpful performance tuning feature. By default, this feature is disabled. We may enable it by:
  1. Powershell script
  2. STSADM command
  3. using code

Enable developer dashboard SharePoint 2016/2013 using PowerShell script

 
We may easily enable or disable developer dashboard in SharePoint using PowerShell script as below,
 
Enable Developer Dashboard SharePoint
  1. $var = Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;  
  2. $var.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On  
  3. $var.Update()   
Enable on Demand
  1. $var.DisplayLevel = ‘OnDemand’;    
Display level for Developer dashboard can also be set as 'OnDemand'.
 
Disable Developer Dashboard SharePoint
  1. $var = Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;  
  2. $var.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off  
  3. $var.Update()   
Just and On/Off and it can be enabled or disabled.
 

Enable developer dashboard SharePoint 2010 STSADM

 
Below is the STSADM command to enable or disable developer dashboard in SharePoint.
 
Enable Developer Dashboard SharePoint
 
stsadm -o setproperty -pn developer-dashboard -pv on
 
Disable Developer Dashboard
 
stsadm -o setproperty -pn developer-dashboard -pv off
 
Enable on Demand (Recommended approach will be OnDemand)
 
stsadm -o setproperty -pn developer-dashboard -pv OnDemand
 

Enable developer dashboard SharePoint using Server Object Model

 
By using SharePoint server object model, we may do the enable or disable developer dashboard in SharePoint as below,
  1. using Microsoft.SharePoint;  
  2. using Microsoft.SharePoint.Administration;  
  3. SPDeveloperDashboardSettings settings = SPWebService.ContentService.DeveloperDashboardSettings;  
  4. settings.DisplayLevel = SPDeveloperDashboardLevel.On;  
  5. settings.TraceEnabled = true;  
  6. settings.Update();   

Developer Dashboard on custom master page in SharePoint

 
To use Developer Dashboard on custom master pages, keep the Developer Dashboard Launcher and page rendering control on the custom master page.
 
For the developer dashboard launcher,
  1. <Sharepoint:DeveloperDashboardLauncher ID="DeveloperDashboardLauncher" NavigateUrl="javascript:ToggleDeveloperDashboard()" runat="server" ImageUrl="/_layouts/images/fgimg.png" Text="<%$Resources:wss,multipages_launchdevdashalt_text%>" OffsetX=0 OffsetY=222 Height=16 Width=16 />  
Page Rendering Control
  1. <SharePoint:DeveloperDashboard runat="server" />  
Where on the page it will reflect and render the output.
 

Viewing Logs with Developer Dashboard

 
Using the below steps, we can view the ULS logs in developer dashboard.
  1. Log to your site
  2. From the right side of the ribbon, click on developer dashboard. Developer dashboard will pop up in new window.
  3. Browse the link to troubleshoot. It will start logging the session requests.
  4. Select the request you want to investigate and click on related ULS log entries.
Recommendation
 
Most important, it gets enabled to the whole farm and is not particular to any site collection. So, it's recommended to use in test environments. Then turn it off in production environments.
 

Summary

 
Developer dashboard is very helpful to developers in writing performance tuned code and the ability to debug errors.