SPMonitoredScope in SharePoint Applications

1 comment
Hi All,

In a following post , we will look What are the usages of SPMonitoredScope.

when an unexplained performance issue faced, it was sometimes difficult to isolate the problem and determine its root cause.Often developers/administrators would spend a lot of time determining where their failure points and performance bottlenecks were.

In SharePoint 2010 Microsoft introduced SPMonistoredScope class,
To allow developers to designate portions of their code ,So that they can monitor usage statistics in the Unified Logging Service (ULS) logs and the Developer Dashboard.

  • The SPMonitoredScope class resides in the Microsoft.SharePoint.Utilities namespace.
  • SPMonitoredScope is very easy to use. A developer simply needs to “wraps” the section of code to be monitored.As the code is executed, the measured statistics are written to the ULS logs as well as to the Developer Dashboard. This allows information about the component and the page where it resides to be immediately available to the developer and to the system administrator.


Syntax:
using (new SPMonitoredScope(“My MonitoredScope Name”))
{
   MyCustomMethod();
}

Nesting Monitored Scopes:
using(new SPMonitoredScope("1 MonitoredScope"))
{
MyFirstMethod();
using(new SPMonitoredScope(1.1 MonitoredScope"))
{
// some code
using(new SPMonitoredScope(1.1 MonitoredScope"))
{
 // some code
}
}
}

Limitations:
  1. Only calls to SharePoint databases are captured.
  2. Only the code wrapped with SPMonitoredScope that resides on the front-end Web server appears on the Developer Dashboard. Code that executes on application servers only displays the SPMonitoredScope information in the ULS logs of the computer that the code is running on.
  3. SPMonitoredScope cannot be used in sandboxed solutions.

Related Post

1 comment: