WebThreadInformation Clase

Definición

Proporciona información sobre el estado de un subproceso en un proceso de ASP.NET.

public ref class WebThreadInformation sealed
public sealed class WebThreadInformation
type WebThreadInformation = class
Public NotInheritable Class WebThreadInformation
Herencia
WebThreadInformation

Ejemplos

El ejemplo de código siguiente tiene dos partes. La primera es un extracto de un archivo de configuración que permite que ASP.NET use un evento personalizado que use el WebThreadInformation tipo . En el segundo se muestra cómo implementar el evento personalizado que usa el WebThreadInformation tipo .

Asegúrese de que el evento personalizado se genera en el momento adecuado, es decir, cuando se genere el evento de mantenimiento del sistema equivalente que reemplace.

<healthMonitoring  
    heartBeatInterval="0" enabled="true">  

  <profiles>  
    <add name="Custom"   
      minInstances="1"   
      maxLimit="Infinite"   
      minInterval="00:00:00" />  
  </profiles>  

  <eventMappings>  

    <add   
      name="SampleWebThreadInformation"   
type="SamplesAspNet.SampleWebThreadInformation,webthreadinformation, Version=1.0.1782.29648, Culture=neutral, PublicKeyToken=b3283a2de7dd3f27, processorArchitecture=MSIL" />  

  </eventMappings>  

  <rules>  

    <add name="Custom Web Thread Info Event"   
      eventName="SampleWebThreadInformation"   
      provider="EventLogProvider"  
      profile="Custom" />  

  </rules>  

</healthMonitoring>  

using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebErrorstEvent that uses the 
    // WebThreadInformation. 
    public class SampleWebThreadInformation :
        WebErrorEvent
    {
        private StringBuilder eventInfo;

        // Instantiate events identified 
        // only by their event code.
        public SampleWebThreadInformation(
            string msg, object eventSource,
            int eventCode, Exception e)
            :
            base(msg, eventSource, eventCode, e)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
            "Event created at: {0}",
            EventTime.ToString()));
        }

        // Raises the event.
        public override void Raise()
        {
            // Perform custom processing. 
            eventInfo.Append(string.Format(
                "Event raised at: {0}",
               EventTime.ToString()));
            // Raise the event.
            base.Raise();
        }

        // Get the impersonation mode.
        public string GetThreadImpersonation()
        {
            return (string.Format(
                "Is impersonating: {0}",
                ThreadInformation.IsImpersonating.ToString()));
        }

        // Get the stack trace.
        public string GetThreadStackTrace()
        {
            return (string.Format(
                "Stack trace: {0}",
                ThreadInformation.StackTrace));
        }

        // Get the account name.
        public string GetThreadAccountName()
        {
            return (string.Format(
                "Request user host address: {0}",
                ThreadInformation.ThreadAccountName));
        }

        // Get the task Id.
        public string GetThreadId()
        {
            // Get the request principal.
            return (string.Format(
                "Thread Id: {0}",
                ThreadInformation.ThreadID.ToString()));
        }


        // Formats Web request event information.
        public override void FormatCustomEventDetails(
         WebEventFormatter formatter)
        {

            // Add custom data.

            formatter.AppendLine("");
            formatter.AppendLine(
                "Custom Thread Information:");

            formatter.IndentationLevel += 1;

            // Display the thread information obtained 
            formatter.AppendLine(GetThreadImpersonation());
            formatter.AppendLine(GetThreadStackTrace());
            formatter.AppendLine(GetThreadAccountName());
            formatter.AppendLine(GetThreadId());
            formatter.IndentationLevel -= 1;

            formatter.AppendLine(eventInfo.ToString());
        }

    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management



' Implements a custom WebErrorstEvent that uses the 
' WebThreadInformation. 

Public Class SampleWebThreadInformation
   Inherits WebErrorEvent
   Private eventInfo As StringBuilder
   
   
   ' Instantiate events identified 
   ' only by their event code.
    Public Sub New(ByVal msg As String, _
    ByVal eventSource As Object, _
    ByVal eventCode As Integer, ByVal e As Exception)
        MyBase.New(msg, eventSource, eventCode, e)
        ' Perform custom initialization.
        eventInfo = New StringBuilder()
        eventInfo.Append(String.Format("Event created at: {0}", EventTime.ToString()))
    End Sub
   
   
   
   ' Raises the event.
   Public Overrides Sub Raise()
      ' Perform custom processing. 
        eventInfo.Append(String.Format( _
        "Event raised at: {0}", EventTime.ToString()))
      ' Raise the event.
      MyBase.Raise()
   End Sub
   
   ' Get the impersonation mode.
   Public Function GetThreadImpersonation() As String
        Return String.Format( _
        "Is impersonating: {0}", _
        ThreadInformation.IsImpersonating.ToString())
   End Function 'GetThreadImpersonation
   
   ' Get the stack trace.
   Public Function GetThreadStackTrace() As String
        Return String.Format( _
        "Stack trace: {0}", _
        ThreadInformation.StackTrace)
   End Function 'GetThreadStackTrace
   
   ' Get the account name.
   Public Function GetThreadAccountName() As String
        Return String.Format( _
        "Request user host address: {0}", _
        ThreadInformation.ThreadAccountName)
   End Function 'GetThreadAccountName
   
   ' Get the task Id.
   Public Function GetThreadId() As String
      ' Get the request principal.
        Return String.Format( _
        "Thread Id: {0}", _
        ThreadInformation.ThreadID.ToString())
   End Function 'GetThreadId
   
   ' Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter As WebEventFormatter)

        ' Add custom data.
        formatter.AppendLine("")
        formatter.AppendLine( _
        "Custom Thread Information:")

        formatter.IndentationLevel += 1

        ' Display the thread information obtained 
        formatter.AppendLine(GetThreadImpersonation())
        formatter.AppendLine(GetThreadStackTrace())
        formatter.AppendLine(GetThreadAccountName())
        formatter.AppendLine(GetThreadId())
        formatter.IndentationLevel -= 1

        formatter.AppendLine(eventInfo.ToString())
    End Sub

End Class

Comentarios

ASP.NET supervisión de estado permite al personal de producción y operaciones administrar las aplicaciones web implementadas. El System.Web.Management espacio de nombres contiene los tipos de eventos de mantenimiento responsables de empaquetar los datos de estado de mantenimiento de la aplicación y los tipos de proveedor responsables de procesar estos datos. También contiene tipos auxiliares que ayudan durante la administración de eventos de mantenimiento.

Las instancias de la WebThreadInformation clase contienen información que se obtiene mediante el WebErrorEvent tipo o el WebRequestErrorEvent tipo .

La aplicación necesita los permisos adecuados para acceder a la información protegida proporcionada por este tipo.

Nota:

En la mayoría de los casos, podrá usar los tipos de supervisión de estado ASP.NET tal como se implementa y controlará el sistema de supervisión de estado especificando valores en la healthMonitoring sección de configuración. También puede derivar de los tipos de supervisión de estado para crear sus propios eventos y proveedores personalizados. Para obtener un ejemplo de creación de una clase de eventos personalizada, consulte el ejemplo proporcionado en este tema.

Propiedades

IsImpersonating

Obtiene el modo de suplantación de subproceso actual.

StackTrace

Obtiene el seguimiento de la pila administrada por el subproceso actual.

ThreadAccountName

Obtiene el nombre de cuenta del subproceso.

ThreadID

Obtiene el identificador del subproceso actual.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
FormatToString(WebEventFormatter)

Da formato a la información relacionada con el subproceso.

GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Consulte también