Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)

public static SPDiagnosticsService Local { get; }

Property value

Type: Microsoft.SharePoint.Administration.SPDiagnosticsService
An SPDiagnosticsService object that represents the service instance.

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).

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.

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();
        }
    }
}
Show:
© 2015 Microsoft