共用方式為


SPDiagnosticsService.Local property

會取得 object,代表目前伺服器陣列中執行診斷服務執行個體。

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

Syntax

'宣告
Public Shared ReadOnly Property Local As SPDiagnosticsService
    Get
'用途
Dim value As SPDiagnosticsService

value = SPDiagnosticsService.Local
public static SPDiagnosticsService Local { get; }

Property value

Type: Microsoft.SharePoint.Administration.SPDiagnosticsService
SPDiagnosticsService 物件代表的服務執行個體。

備註

如果您的應用程式其中一個伺服器陣列中前端網頁伺服器上執行,則此屬性會傳回SPDiagnosticsService類別的執行個體。如果不存在的服務執行個體,當您存取此屬性時,本機伺服器上建立執行個體,並變更傳播至伺服器陣列中的所有伺服器。

如果您未連線至伺服器陣列中的前端網頁伺服器,則屬性會傳回a null reference (Nothing in Visual Basic)。

Examples

下列範例會顯示主控台應用程式也可以在管理中心內的診斷記錄] 頁面上的 [追蹤記錄檔] 區段中找到該報告資訊。

Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration

Module ConsoleApp
   Sub Main()
      Dim diagSvc As SPDiagnosticsService = SPDiagnosticsService.Local
      If diagSvc Is Nothing Then
         Console.WriteLine("You are not connected to a front-end server.")
      Else
         Console.WriteLine("Trace log path: {0}", diagSvc.LogLocation)
         Console.WriteLine("Days to keep log files: {0}", diagSvc.DaysToKeepLogs)
         If diagSvc.LogMaxDiskSpaceUsageEnabled Then
            Console.WriteLine("Maximum amount of storage to use: {0}", diagSvc.LogDiskSpaceUsageGB)
         Else
            Console.WriteLine("Storage space is not restricted.")
      End If
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
            if (diagSvc == null)
            {
                Console.WriteLine("You are not connected to a front-end server.");
            }
            else
            {
                Console.WriteLine("Trace log path: {0}", diagSvc.LogLocation);
                Console.WriteLine("Days to keep log files: {0}", diagSvc.DaysToKeepLogs);
                if (diagSvc.LogMaxDiskSpaceUsageEnabled)
                    Console.WriteLine("Maximum amount of storage to use: {0}", diagSvc.LogDiskSpaceUsageGB);
                else
                    Console.WriteLine("Storage space is not restricted.");
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}

請參閱

參照

SPDiagnosticsService class

SPDiagnosticsService members

Microsoft.SharePoint.Administration namespace