SPDiagnosticsService.GetItems 方法

请注意:此 API 现在已过时。

获取注册到服务器场的所有类别的集合。

命名空间:  Microsoft.SharePoint.Administration
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<ObsoleteAttribute("Use SPDiagnosticsServiceBase.Categories")> _
Public Function GetItems As IEnumerable(Of IDiagnosticsLevel)
用法
Dim instance As SPDiagnosticsService
Dim returnValue As IEnumerable(Of IDiagnosticsLevel)

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

返回值

类型:System.Collections.Generic.IEnumerable<IDiagnosticsLevel>
IEnumerable<T>IDiagnosticsLevel 对象的集合。

实现

IDiagnosticsManager.GetItems()

示例

下面的示例演示一个控制台应用程序,调用GetItems方法来获取有关注册的服务器场的所有类别信息。从控制台应用程序的输出是相同 (除了格式的差异) 与 Stsadm 命令行工具与这些开关一起使用时的输出。

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();
      }
   }
}

另请参阅

引用

SPDiagnosticsService 类

SPDiagnosticsService 成员

Microsoft.SharePoint.Administration 命名空间