SPDiagnosticsServiceBase class
提供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)
Syntax
'宣告
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public MustInherit Class SPDiagnosticsServiceBase _
Inherits SPService _
Implements IBackupRestoreConfiguration, IBackupRestore
'用途
Dim instance As SPDiagnosticsServiceBase
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public abstract class SPDiagnosticsServiceBase : SPService,
IBackupRestoreConfiguration, IBackupRestore
備註
SPDiagnosticsServiceBase類別為抽象基底類別的協力廠商開發人員撰寫具體指明,以提供自訂的診斷類別,並使用WriteTrace及WriteEvent方法,來執行記錄時可繼承。如需詳細資訊,請參閱 < Using the Trace Logging API。
Examples
下列範例會顯示一個實作的診斷服務。請注意CategoryId列舉為ProvideAreas方法所建立的類別的值任意和使用只為了便於說明。您可以建立類別以符合您自己的用途。
using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Administration;
namespace Contoso.Diagnostics
{
public enum CategoryId
{
None = 0,
Deployment = 100,
Provisioning = 200,
CustomAction = 300,
Rendering = 400,
WebPart = 500
}
[System.Runtime.InteropServices.GuidAttribute("DBEEB5AB-C5A7-46B5-A2BB-5581F960C333")]
class DiagnosticsService:SPDiagnosticsServiceBase
{
private static string DiagnosticsAreaName = "Contoso";
public DiagnosticsService()
{
}
public DiagnosticsService(string name, SPFarm farm)
:base(name, farm)
{
}
protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
{
List<SPDiagnosticsCategory> categories = new List<SPDiagnosticsCategory>();
foreach (string catName in Enum.GetNames(typeof(CategoryId)))
{
uint catId = (uint)(int)Enum.Parse(typeof(CategoryId), catName);
categories.Add(new SPDiagnosticsCategory(catName, TraceSeverity.Verbose, EventSeverity.Error, 0, catId));
}
yield return new SPDiagnosticsArea(DiagnosticsAreaName, categories);
}
public static DiagnosticsService Local
{
get
{
return SPDiagnosticsServiceBase.GetLocal<DiagnosticsService>();
}
}
public SPDiagnosticsCategory this[CategoryId id]
{
get
{
return Areas[DiagnosticsAreaName].Categories[id.ToString()];
}
}
}
}
下列程式碼範例顯示如何使用診斷服務,以及在追蹤記錄檔中寫入項目。
Sample code provided by:James 堡壘,Microsoft Corporation。
using System;
using Microsoft.SharePoint.Administration;
namespace Contoso.Diagnostics
{
class Program
{
static void Main(string[] args)
{
DiagnosticsService myULS = new DiagnosticsService ("SP Provisioning", SPContext.Current.Site.WebApplication.Farm);
if (myULS != null)
{
SPDiagnosticsCategory cat = new SPDiagnosticsCategory ("SP Provisioning", TraceSeverity.High, TraceSeverity.Verbose);
cat = myULS[CategoryId.Provisioning];
string format = "Tracing test of {0} service";
myULS.WriteTrace(1, cat, TraceSeverity.Verbose, format, myULS.TypeName);
}
Console.ReadLine();
}
}
}
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.
請參閱
參照
SPDiagnosticsServiceBase members
Microsoft.SharePoint.Administration namespace