Compartir a través de


Creación de un servicio de diagnóstico personalizado

Última modificación: viernes, 16 de abril de 2010

Hace referencia a: SharePoint Foundation 2010

En este artículo
Servicio de diagnóstico personalizado
Uso de cadenas localizadas para mensajes de registro
Registro del servicio de diagnóstico en SharePoint Foundation

En este artículo se proporciona un ejemplo de cómo crear un servicio de diagnóstico para permitir a un programador usar la API ULS mejorada incluida en Microsoft SharePoint Foundation 2010.

Servicio de diagnóstico personalizado

Un servicio de diagnóstico personalizado debe heredar de la clase SPDiagnosticsServiceBase que se encuentra en el espacio de nombres Microsoft.SharePoint.Administration.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Internal.Diagnostics;
using Microsoft.SharePoint.Administration;
using System.Runtime.InteropServices;
namespace SampleDiagnosticServices
{
    // always create your own Guid attribute when deriving from ULSDiagnosticsServiceBase
    // The Guid attribute is required by the WSS ConfigDB
    [Guid("5C622C71-A6F8-4527-B05B-4D7ED4A69760")]
    public class O14ULS : ULSDiagnosticsServiceBase
    {
        public O14ULS()
        {
        }
        public O14ULS(string name, SPFarm parent)
            : base(name, parent)
        {
        }
        public static O14ULS Local
        {
            get { return SPDiagnosticsServiceBase.GetLocal<O14ULS>(); }
        }
        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
        {
            // The "0, 0, false" parameters are NOT optional when using ULSDiagnosticsServiceBase.

            yield return new SPDiagnosticsArea("ULS Area 1", 0, 0, false,
                new List<SPDiagnosticsCategory>()
                {
                    new SPDiagnosticsCategory("Category 1", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 2", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 3", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 4", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 5", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 6", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                }
            );
            yield return new SPDiagnosticsArea("ULS Area 2",
                new List<SPDiagnosticsCategory>()
                {
                    new SPDiagnosticsCategory("Category 1", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 2", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 3", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 4", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 5", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                    new SPDiagnosticsCategory("Category 6", TraceSeverity.Verbose, EventSeverity.Verbose, 0, 0, false),
                }
            );
        }

Uso de cadenas localizadas para mensajes de registro

En algunos casos, puede ser necesario usar cadenas localizadas para mensajes que son relevantes para la referencia cultural en la que está instalado Microsoft SharePoint Foundation 2010. A fin de proporcionar los mensajes localizados en la interfaz de usuario administrativa, debe invalidar el método ResourceDll() y hacer que proporcione una ruta de acceso a la dll personalizada.

El método siguiente proporciona el servicio de diagnóstico con la ubicación del archivo dll

protected override string ResourceDll
        {
            get
            {
                // optional: the developer could provide the path to an actual resource dll to get localized names
                return null;
            }
        }

Registro del servicio de diagnóstico en SharePoint Foundation

A fin de que SharePoint Foundation 2010 use el servicio de diagnóstico que se creó, deberá registrarlo. Sin embargo, antes de hacerlo, cada servidor front-end web del conjunto o granja de servidores de SharePoint Foundation 2010 debe tener el ensamblado instalado y registrado en la memoria caché global de ensamblados (GAC).

Una vez instalado el ensamblado, puede registrar el servicio de SharePoint mediante la creación de una clave del Registro, o mediante un comando de Windows PowerShell.

Clave del Registro: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\Services

PS C:\<AssemblyLocation> [void][System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.Office.Server’)
[Microsoft.Office.Server.Administration.DiagnosticsService]::Local.Update()

Vea también

Conceptos

Escritura en el registro de seguimiento desde el código personalizado

Introducción al registro del sistema de creación de registros unificado (ULS)