SPDiagnosticsService class

Provides a diagnostic-logging category manager for Microsoft SharePoint Foundation.

Inheritance hierarchy


Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


<GuidAttribute("CB4D9DFD-60CF-4d6a-8615-F8A8448452CB")> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class SPDiagnosticsService _
    Inherits SPDiagnosticsServiceBase _
    Implements IDiagnosticsManager
Dim instance As SPDiagnosticsService
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPDiagnosticsService : SPDiagnosticsServiceBase, 


This class enables you to do programmatically what you can do manually in the user interface by using the Trace Log and Event Throttling sections on the Central Administration Diagnostics Logging page. The administrator can also configure these settings by using the Windows PowerShell cmdlets Get-SPDiagnosticConfig and Set-SPDiagnosticConfig.

Trace logs receive informative messages about the execution of an application that has been instrumented for tracing. Application tracing is often used to measure product performance and to diagnose errors. To manage the location of trace logs and the number of days to store them programmatically, start by getting an instance of the SPDiagnosticsService class from the static Local property. Then set the LogLocation and DaysToKeepLogs properties of the object. To restrict the amount of disk space that the logs use, set the LogMaxDiskSpaceUsageEnabled property to true and specify the maximum storage space to use by setting the LogDiskSpaceUsageGB property. Finally, propagate the new configuration throughout the server farm by calling the Update() method.

Event throttling is a term that refers to controlling the rate at which events are captured in the Windows event log and in trace logs. Events are managed by categories, and separate reporting thresholds are maintained for each type of log. To set thresholds for a particular category, you must first get an instance of the SPDiagnosticsService class by accessing the static Local property. Then use the ds.Areas["AreaName"].Categories["CatName"].TraceSeverity to modify the severity and call ds.Update() to commit.

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also


SPDiagnosticsService members

Microsoft.SharePoint.Administration namespace

Other resources

Trace Logs