WebRequestErrorEvent 类

定义

定义承载有关 Web 请求错误信息的事件。

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
继承
派生

示例

下面的代码示例有两个部分。 第一部分是配置文件的摘录,使 ASP.NET 能够使用自定义事件。 第二部分演示如何从 WebRequestErrorEvent 类派生以创建自定义事件。

<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

注解

WebRequestErrorEvent如果在 Web 请求期间发生错误,则会引发此错误。 应用程序应使用此事件来获取由 WebRequestInformation 该类和 WebThreadInformation 类定义的与请求相关的信息。

备注

在大多数情况下,你将使用标准 ASP.NET 运行状况监视类型,并通过设置healthMonitoring配置部分来控制其行为。 还可以创建自定义类型,如下一个示例所示。 如果创建自定义事件类型,并且需要添加自己的信息,请自定义 FormatCustomEventDetails 该方法,这将避免覆盖或篡改敏感信息。

构造函数

WebRequestErrorEvent(String, Object, Int32, Exception)

使用指定的事件参数对 WebRequestErrorEvent 类进行初始化。

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

使用指定的事件参数对 WebRequestErrorEvent 类进行初始化。

属性

ErrorException

获取与此错误关联的 Exception

(继承自 WebBaseErrorEvent)
EventCode

获取与该事件关联的代码值。

(继承自 WebBaseEvent)
EventDetailCode

获取事件详细信息代码。

(继承自 WebBaseEvent)
EventID

获取与事件关联的标识符。

(继承自 WebBaseEvent)
EventOccurrence

获取表示事件发生次数的计数器。

(继承自 WebBaseEvent)
EventSequence

获取应用程序已引发事件的次数。

(继承自 WebBaseEvent)
EventSource

获取引发事件的对象。

(继承自 WebBaseEvent)
EventTime

获取引发事件的时间。

(继承自 WebBaseEvent)
EventTimeUtc

获取引发事件的时间。

(继承自 WebBaseEvent)
Message

获取描述事件的消息。

(继承自 WebBaseEvent)
ProcessInformation

获取有关 ASP.NET 应用程序承载进程的信息。

(继承自 WebManagementEvent)
RequestInformation

获取应用程序请求信息。

ThreadInformation

获取应用程序线程信息。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
FormatCustomEventDetails(WebEventFormatter)

提供事件信息的标准格式设置。

(继承自 WebBaseEvent)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IncrementPerfCounters()

内部使用以递增相关性能计数器。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Raise()

通过将事件已发生这一情况通知任何已配置的提供程序来引发事件。

(继承自 WebBaseEvent)
ToString()

为显示而对事件信息进行格式化。

(继承自 WebBaseEvent)
ToString(Boolean, Boolean)

为显示而对事件信息进行格式化。

(继承自 WebBaseEvent)

适用于

另请参阅