共用方式為


SPDiagnosticsService Class

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

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPPersistedUpgradableObject
        Microsoft.SharePoint.Administration.SPService
          Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase
            Microsoft.SharePoint.Administration.SPDiagnosticsService

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

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

Remarks

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

Reference

SPDiagnosticsService Members

Microsoft.SharePoint.Administration Namespace

Other Resources

Trace Logs