WebThreadInformation Klass

Definition

Innehåller information om tillståndet för en tråd i en ASP.NET process.

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

Exempel

I följande kodexempel finns två delar. Den första är ett utdrag av en konfigurationsfil som gör att ASP.NET kan använda en anpassad händelse som använder WebThreadInformation typ. Den andra visar hur du implementerar den anpassade händelse som använder WebThreadInformation typen.

Se till att din anpassade händelse aktiveras vid rätt tidpunkt, dvs. när motsvarande systemhälsohändelse som den ersätter skulle aktiveras.

<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

Kommentarer

ASP.NET hälsoövervakning gör det möjligt för produktions- och driftpersonal att hantera distribuerade webbprogram. Namnområdet System.Web.Management innehåller de hälsohändelsetyper som ansvarar för att paketera programhälsostatusdata och de leverantörstyper som ansvarar för bearbetning av dessa data. Den innehåller också stödtyper som hjälper till vid hantering av hälsohändelser.

Instanser av WebThreadInformation klassen innehåller information som hämtas med antingen WebErrorEvent typen eller WebRequestErrorEvent typen.

Ditt program behöver lämpliga behörigheter för att få åtkomst till skyddad information som tillhandahålls av den här typen.

Note

I de flesta fall kommer du att kunna använda ASP.NET hälsoövervakningstyper som implementerats, och du kommer att kontrollera hälsoövervakningssystemet genom att ange värden i konfigurationsavsnittet healthMonitoring. Du kan också härleda från hälsoövervakningstyperna för att skapa egna anpassade händelser och leverantörer. Ett exempel på hur du skapar en anpassad händelseklass finns i exemplet i det här avsnittet.

Egenskaper

Name Description
IsImpersonating

Hämtar det aktuella tråd-personifieringsläget.

StackTrace

Hämtar den aktuella trådhanterade stackspårningen.

ThreadAccountName

Hämtar trådkontots namn.

ThreadID

Hämtar den aktuella trådidentifieraren.

Metoder

Name Description
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
FormatToString(WebEventFormatter)

Formaterar trådrelaterad information.

GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för

Se även