Condividi tramite


SPDiagnosticsService.GetItems Method

NOTE: This API is now obsolete.

Gets a collection of all categories registered with the server farm.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")> _
Public Function GetItems As IEnumerable(Of IDiagnosticsLevel)
'Usage
Dim instance As SPDiagnosticsService
Dim returnValue As IEnumerable(Of IDiagnosticsLevel)

returnValue = instance.GetItems()
[ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")]
public IEnumerable<IDiagnosticsLevel> GetItems()

Return Value

Type: System.Collections.Generic.IEnumerable<IDiagnosticsLevel>
A IEnumerable<T> collection of IDiagnosticsLevel objects.

Implements

IDiagnosticsManager.GetItems()

Examples

The following example shows a console application that calls the GetItems method to obtain information about all categories that are registered with the server farm. The output from the console application is identical (except for differences in format) to the output from the Stsadm command-line tool when used with these switches.

stsadm -o listlogginglevels -showhidden
Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration

Module ConsoleApp

   Sub Main()

      Dim diagnostics As SPDiagnosticsService = SPDiagnosticsService.Local
      If diagnostics Is Nothing Then
         Console.WriteLine("You are not connected to a front-end server.")
      Else
         Console.WriteLine("  {0,-30} {1,-12} {2,-12}", _
                           "Category Name", "Trace Level", "Event Level")
         Dim sep As String = ""
         Console.WriteLine(sep.PadLeft(60, "-"))
         Dim levels As IEnumerable(Of IDiagnosticsLevel) = diagnostics.GetItems()
         Dim level As IDiagnosticsLevel
         For Each level In levels
            Console.WriteLine("  {0,-30}  {1,-12} {2,-12}", _
                              level.Id, _
                              level.TraceSeverity.ToString(), _
                              level.EventSeverity.ToString())
         Next
      End If

      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

End Module
using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         SPDiagnosticsService diagnostics = SPDiagnosticsService.Local;
         if (diagnostics == null)
         {
            Console.WriteLine("You are not connected to a front-end server.");
         }
         else
         {
            Console.WriteLine("  {0,-30} {1,-12} {2,-12}", 
                              "Category Name", "Trace Level", "Event Level");
            string sep = "";
            Console.WriteLine(sep.PadLeft(60, '-'));
            IEnumerable<IDiagnosticsLevel> levels = diagnostics.GetItems();
            foreach (IDiagnosticsLevel level in levels)
            {
               Console.WriteLine("  {0,-30}  {1,-12} {2,-12}", 
                                 level.Id, 
                                 level.TraceSeverity.ToString(), 
                                 level.EventSeverity.ToString());
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPDiagnosticsService Class

SPDiagnosticsService Members

Microsoft.SharePoint.Administration Namespace