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)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Shared ReadOnly Property Local As SPDiagnosticsService
    Get
'Usage
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 your application is running on 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("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();
        }
    }
}

See Also

Reference

SPDiagnosticsService Class

SPDiagnosticsService Members

Microsoft.SharePoint.Administration Namespace