SPDiagnosticsService.Local Property

Gets an object that represents the instance of the Diagnostics Service that is currently running in the server farm.

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
An SPDiagnosticsService object that represents the service instance.

Remarks

If you are connected to one of the front-end Web servers in the farm, this property returns an instance of the SPDiagnosticsService class. If an instance of the service does not exist, when you access this property, an instance is created on the local server and the change propagates to all servers in the server farm.

If you are not connected to a front-end Web server in the server farm, the property returns a null reference (Nothing in Visual Basic).

Examples

The following example shows a console application that reports information that you can also find in the Trace Log section on the Central Administration Diagnostics Logging page.

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("Number of log files: {0}", diagSvc.LogsToKeep)
         Console.WriteLine("Number of minutes to use a log file: {0}", diagSvc.LogCutInterval)
      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("Number of log files: {0}", diagSvc.LogsToKeep);
            Console.WriteLine("Number of minutes to use a log file: {0}", diagSvc.LogCutInterval);
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPDiagnosticsService Class

SPDiagnosticsService Members

Microsoft.SharePoint.Administration Namespace