Udostępnij za pośrednictwem


WebThreadInformation Klasa

Definicja

Zawiera informacje o stanie wątku w procesie ASP.NET.

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

Przykłady

Poniższy przykład kodu zawiera dwie części. Pierwszy to fragment pliku konfiguracji, który umożliwia ASP.NET używanie zdarzenia niestandardowego, które używa WebThreadInformation typu. Drugi pokazuje, jak zaimplementować zdarzenie niestandardowe, które używa WebThreadInformation typu.

Upewnij się, że zdarzenie niestandardowe jest zgłaszane w odpowiednim czasie, czyli wtedy, gdy zostanie podniesione równoważne zdarzenie kondycji systemu, które zastąpi.

<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

Uwagi

ASP.NET monitorowanie kondycji umożliwia pracownikom produkcyjnym i operacyjnym zarządzanie wdrożonych aplikacji internetowych. System.Web.Management Przestrzeń nazw zawiera typy zdarzeń kondycji odpowiedzialne za pakowanie danych o stanie kondycji aplikacji i typów dostawców odpowiedzialnych za przetwarzanie tych danych. Zawiera również typy pomocnicze, które pomagają podczas zarządzania zdarzeniami kondycji.

WebThreadInformation Wystąpienia klasy zawierają informacje uzyskane przy użyciu WebErrorEvent typu lub WebRequestErrorEvent typu.

Aplikacja potrzebuje odpowiednich uprawnień, aby uzyskać dostęp do chronionych informacji dostarczonych przez ten typ.

Uwaga

W większości przypadków będzie można użyć ASP.NET typów monitorowania kondycji zgodnie z implementacją i będzie kontrolować system monitorowania kondycji, określając wartości w healthMonitoring sekcji konfiguracji. Możesz również pochodzić z typów monitorowania kondycji w celu utworzenia własnych niestandardowych zdarzeń i dostawców. Przykład tworzenia niestandardowej klasy zdarzeń można znaleźć w przykładzie podanym w tym temacie.

Właściwości

IsImpersonating

Pobiera bieżący tryb personifikacji wątku.

StackTrace

Pobiera bieżący ślad stosu zarządzanego przez wątki.

ThreadAccountName

Pobiera nazwę konta wątku.

ThreadID

Pobiera bieżący identyfikator wątku.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
FormatToString(WebEventFormatter)

Formatuje informacje dotyczące wątków.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też