Partager via


SPDiagnosticsService.GetItem - Méthode (String)

Remarque : cette API est désormais obsolète.

Renvoie un objet IDiagnosticsLevel qui représente une catégorie de rapport avec un nom spécifié.

Espace de noms :  Microsoft.SharePoint.Administration
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
<ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")> _
Public Function GetItem ( _
    name As String _
) As IDiagnosticsLevel
'Utilisation
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
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.Administration.IDiagnosticsLevel
Objet IDiagnosticsLevel qui représente une catégorie de rapport. Si une catégorie avec le nom fourni n'est pas enregistrée dans la batterie de serveurs, la méthode retourne une référence Null (Rien dans Visual Basic).

Implémentations

IDiagnosticsManager.GetItem(String)

Remarques

La chaîne passée en tant qu'argument peut être un nom de catégorie localisée (la valeur de la propriété IDiagnosticsLevel.Name ) ou un nom de catégorie non localisé (la valeur de la propriété IDiagnosticsLevel.Id ). En utilisant le nom non localisé rend votre code portable entre paramètres régionaux.

Exemples

L'exemple suivant montre une application de console qui imprime des informations sur la catégorie d'exécution à la 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();
      }
   }
}

Voir aussi

Référence

SPDiagnosticsService classe

SPDiagnosticsService - Membres

GetItem - Surcharge

Microsoft.SharePoint.Administration - Espace de noms