Språk

WebRequestErrorEvent Klass

Definition

Definierar den händelse som innehåller information om webbbegärandefel.

public ref class WebRequestErrorEvent : System::Web::Management::WebBaseErrorEvent
public class WebRequestErrorEvent : System.Web.Management.WebBaseErrorEvent
type WebRequestErrorEvent = class
    inherit WebBaseErrorEvent
Public Class WebRequestErrorEvent
Inherits WebBaseErrorEvent
Arv
Härledda

Exempel

I följande kodexempel finns två delar. Den första delen är ett utdrag av en konfigurationsfil som gör att ASP.NET kan använda en anpassad händelse. Den andra delen visar hur du härleder från WebRequestErrorEvent klassen för att skapa den anpassade händelsen.

<healthMonitoring enabled="true" heartBeatInterval="0">
  <eventMappings>
    <add  name="SampleWebRequestErrorEvent" type="SamplesAspNet.SampleWebRequestErrorEvent,webrequesterrorevent,Version=1.0.1573.21654, Culture=neutral, PublicKeyToken=63ada862a6c5af13, processorArchitecture=MSIL"/>
  </eventMappings>

  <rules>
    <add
      name="Custom Web Request Error Events"
      eventName="SampleWebRequestErrorEvent"
      provider="EventLogProvider"
      profile="Critical"/>
  </rules>
</healthMonitoring>

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

namespace Samples.AspNet.Management
{
  // Implements a custom WebRequestErrorEvent class. 
    public class SampleWebRequestErrorEvent : 
        WebRequestErrorEvent
    {
        private StringBuilder eventInfo;

        // Invoked in case of events 
        // identified only by their event code.
        public SampleWebRequestErrorEvent(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: ", EventTime.ToString()));
        }

        // Invoked in case of events identified 
        // by their event code.and related event 
        // detailed code.
        public SampleWebRequestErrorEvent(
            string msg, object eventSource, 
            int eventCode, int detailedCode, 
            Exception e):
          base(msg, eventSource, 
            eventCode, detailedCode, e)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
                "Event created at: ", EventTime.ToString()));
        }


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

        // Obtains the current request information.
        public string GetRequestInfo()
        {
            string reqInfo = GetRequestInfo();
            return reqInfo;
        }

        // Obtains the current thread information.
        public string GetThreadInfo()
        {
            string threadInfo = GetThreadInfo();
            return threadInfo;
        }

        // Obtains the current process information.
        public string GetProcessInfo()
        {
            string procInfo = GetProcessInfo();
            return procInfo;
        }

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

            // Add custom data.
            formatter.AppendLine("");

            formatter.IndentationLevel += 1;
            formatter.AppendLine(
                "** SampleWebRequestEvent Start **");

            // Add custom data.
            formatter.AppendLine(eventInfo.ToString());

            formatter.AppendLine(
                      "** SampleWebRequestEvent End **");
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebRequestErrorEvent class. 
Public Class SampleWebRequestErrorEvent
   Inherits WebRequestErrorEvent
   Private eventInfo As StringBuilder
   
   
   ' Invoked in case of 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: ", _
        EventTime.ToString()))
    End Sub
   
   
   ' Invoked in case of events identified 
   ' by their event code.and related event 
   ' detailed code.
    Public Sub New(ByVal msg As String, _
    ByVal eventSource As Object, _
    ByVal eventCode As Integer, _
    ByVal detailedCode As Integer, _
    ByVal e As Exception)
        MyBase.New(msg, eventSource, _
        eventCode, detailedCode, e)
        ' Perform custom initialization.
        eventInfo = New StringBuilder()
        eventInfo.Append(String.Format( _
        "Event created at: ", _
        EventTime.ToString()))
    End Sub
   
   
   ' Raises the SampleWebRequestErrorEvent.
   Public Overrides Sub Raise()
      ' Perform custom processing. 
        eventInfo.Append(String.Format( _
        "Event raised at: ", _
        EventTime.ToString()))
      ' Raise the event.
      MyBase.Raise()
   End Sub
   
   ' Obtains the current request information.
   Public Function GetRequestInfo() As String
      Dim reqInfo As String = GetRequestInfo()
      Return reqInfo
   End Function 'GetRequestInfo
   
   
   ' Obtains the current thread information.
   Public Function GetThreadInfo() As String
      Dim threadInfo As String = GetThreadInfo()
      Return threadInfo
   End Function 'GetThreadInfo
   
   
   ' Obtains the current process information.
   Public Function GetProcessInfo() As String
      Dim procInfo As String = GetProcessInfo()
      Return procInfo
   End Function 'GetProcessInfo
   
   
   'Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter As WebEventFormatter)
        MyBase.FormatCustomEventDetails(formatter)

        ' Add custom data.
        formatter.AppendLine("")

        formatter.IndentationLevel += 1
        formatter.AppendLine( _
        "** SampleWebRequestEvent Start **")

        ' Add custom data.
        formatter.AppendLine(eventInfo.ToString())

        formatter.AppendLine( _
        "** SampleWebRequestEvent End **")

    End Sub

End Class

Kommentarer

WebRequestErrorEvent Utlöses om ett fel inträffar under en webbbegäran. Ditt program bör använda den här händelsen för att hämta information om begäran enligt definitionen av klasserna WebRequestInformationWebThreadInformation och .

Note

I de flesta fall använder du standardtyperna ASP.NET hälsoövervakning och kontrollerar deras beteende genom att ange konfigurationsavsnittet healthMonitoring. Du kan också skapa anpassade typer, som du ser i nästa exempel. Om du skapar din anpassade händelsetyp och du behöver lägga till din egen information, anpassa FormatCustomEventDetails metoden, undviker du att skriva över eller manipulera känslig systeminformation.

Konstruktorer

Name Description
WebRequestErrorEvent(String, Object, Int32, Exception)

Initierar WebRequestErrorEvent klassen med angivna händelseparametrar.

WebRequestErrorEvent(String, Object, Int32, Int32, Exception)

Initierar WebRequestErrorEvent klassen med angivna händelseparametrar.

Egenskaper

Name Description
ErrorException

Hämtar associerad Exception med felet.

(Ärvd från WebBaseErrorEvent)
EventCode

Hämtar det kodvärde som är associerat med händelsen.

(Ärvd från WebBaseEvent)
EventDetailCode

Hämtar händelseinformationskoden.

(Ärvd från WebBaseEvent)
EventID

Hämtar identifieraren som är associerad med händelsen.

(Ärvd från WebBaseEvent)
EventOccurrence

Hämtar en räknare som representerar antalet gånger händelsen har inträffat.

(Ärvd från WebBaseEvent)
EventSequence

Hämtar antalet gånger som händelsen har skapats av programmet.

(Ärvd från WebBaseEvent)
EventSource

Hämtar objektet som genererar händelsen.

(Ärvd från WebBaseEvent)
EventTime

Hämtar den tid då händelsen skapades.

(Ärvd från WebBaseEvent)
EventTimeUtc

Hämtar den tid då händelsen skapades.

(Ärvd från WebBaseEvent)
Message

Hämtar meddelandet som beskriver händelsen.

(Ärvd från WebBaseEvent)
ProcessInformation

Hämtar information om ASP.NET programvärdprocess.

(Ärvd från WebManagementEvent)
RequestInformation

Hämtar information om programbegäran.

ThreadInformation

Hämtar programtrådsinformationen.

Metoder

Name Description
Equals(Object)

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

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

Tillhandahåller standardformatering av händelseinformationen.

(Ärvd från WebBaseEvent)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
IncrementPerfCounters()

Används internt för att öka relevanta prestandaräknare.

MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
Raise()

Genererar en händelse genom att meddela alla konfigurerade leverantörer att händelsen har inträffat.

(Ärvd från WebBaseEvent)
ToString()

Formaterar händelseinformation i visningssyfte.

(Ärvd från WebBaseEvent)
ToString(Boolean, Boolean)

Formaterar händelseinformation i visningssyfte.

(Ärvd från WebBaseEvent)

Gäller för

Se även