Share via


SPDiagnosticsService.GetItem Method (String)

NOTE: This API is now obsolete.

Returns an IDiagnosticsLevel object that represents a reporting category with a specified name.

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

Syntax

'Declaration
<ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")> _
Public Function GetItem ( _
    name As String _
) As IDiagnosticsLevel
'Usage
Dim instance As SPDiagnosticsService
Dim name As String
Dim returnValue As IDiagnosticsLevel

returnValue = instance.GetItem(name)
[ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")]
public IDiagnosticsLevel GetItem(
    string name
)

Parameters

Return Value

Type: Microsoft.SharePoint.Administration.IDiagnosticsLevel
An IDiagnosticsLevel object that represents a reporting category. If a category with the supplied name is not registered in the farm, the method returns a null reference (Nothing in Visual Basic).

Implements

IDiagnosticsManager.GetItem(String)

Remarks

The string passed as an argument can be either a localized category name (the value of the IDiagnosticsLevel.Name property) or a nonlocalized category name (the value of the IDiagnosticsLevel.Id property). Using the nonlocalized name makes your code portable across locales.

Examples

The following example shows a console application that prints information about the runtime category to the console.

Imports System
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
         Dim level As IDiagnosticsLevel = diagnostics.GetItem("Runtime")
         If Not level Is Nothing Then
            Console.WriteLine("Category name (localized): {0}", level.Name)
            Console.WriteLine("Category name (not localized): {0}", level.Id)
            Console.WriteLine("Least critical event to report to the event log: {0}", _
                              level.EventSeverity.ToString())
            Console.WriteLine("Least critical event to report to the trace log: {0}", _
                               level.TraceSeverity.ToString())
         End If
      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 diagnostics = SPDiagnosticsService.Local;
         if (diagnostics == null)
         {
            Console.WriteLine("You are not connected to a front-end server.");
         }
         else
         {
            IDiagnosticsLevel level = diagnostics.GetItem("Runtime");
            if (level != null)
            {
               Console.WriteLine("Category name (localized): {0}", level.Name);
               Console.WriteLine("Category name (not localized): {0}", level.Id);
               Console.WriteLine("Least critical event to report to the event log: {0}", 
                                 level.EventSeverity.ToString());
               Console.WriteLine("Least critical event to report to the trace log: {0}", 
                                 level.TraceSeverity.ToString());
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPDiagnosticsService Class

SPDiagnosticsService Members

GetItem Overload

Microsoft.SharePoint.Administration Namespace