WebBaseErrorEvent 类

定义

作为所有运行状况监视错误事件的基类。

public ref class WebBaseErrorEvent : System::Web::Management::WebManagementEvent
public class WebBaseErrorEvent : System.Web.Management.WebManagementEvent
type WebBaseErrorEvent = class
    inherit WebManagementEvent
Public Class WebBaseErrorEvent
Inherits WebManagementEvent
继承
派生

示例

下面的代码示例有两个部分。 第一个是配置文件的摘录,它使 ASP.NET 运行状况监视能够使用派生自WebBaseErrorEvent类的事件。 第二个说明如何派生自 WebBaseErrorEvent 类以创建自定义事件。

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

  <providers>  
    <!-- Define the custom provider that   
         processes custom Web request events. -->  
    <add name="SampleWebEventProvider"   
      type="SamplesAspNet.SampleEventProvider,  
      webeventprovider,Version=1.0.1573.18094,   
      Culture=neutral, PublicKeyToken=b5a57a9a9d487cf4,   
      processorArchitecture=MSIL"/>  
  </providers>  

  <eventMappings>  

    <!--  Define the event source that issues custom events.   -->  
    <add  name="SampleWebBaseErrorEvent"      
      type="SamplesAspNet.SampleWebBaseErrorEvent,  
      webbaseerrorevent,Version=1.0.1573.21549, Culture=neutral,     
      PublicKeyToken=2a0b23915ac7352b, processorArchitecture=MSIL"/>  
  </eventMappings>  

  <rules>  
    <!-- Associate custom event with related   
      custom provider -->  
    <add   
       name="Custom Web Base Errors"  
       eventName="SampleWebBaseErrorEvent"   
       provider="SampleWebEventProvider"   
       profile="Custom"/>    
  </rules>  

</healthMonitoring>  

以下代码演示如何从 WebBaseErrorEvent 类派生以创建自定义事件。


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

namespace Samples.AspNet.Management
{
  // Implements a custom WebErrorEvent class. 

    public class SampleWebErrorEvent : WebErrorEvent
    {
        private StringBuilder eventInfo;

        // Invoked in case of events identified 
        // only by their event code.
        public SampleWebErrorEvent(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 SampleWebErrorEvent(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 SampleWebErrorEvent.
        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(
                "** SampleWebErrorEvent Start **");
          
            formatter.AppendLine(eventInfo.ToString());

            formatter.AppendLine(
                "** SampleWebBaseErrorEvent End **");

            formatter.IndentationLevel -= 1;
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebErrorEvent class. 

Public Class SampleWebErrorEvent
   Inherits WebErrorEvent
   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 SampleWebErrorEvent.
   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( _
        "** SampleWebErrorEvent Start **")

        formatter.AppendLine(eventInfo.ToString())

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

        formatter.IndentationLevel -= 1
    End Sub

End Class

注解

ASP.NET 运行状况监视允许生产和运营人员管理已部署的 Web 应用程序。 命名空间 System.Web.Management 包含负责打包应用程序运行状况状态数据的运行状况事件类型和负责处理此数据的提供程序类型。 它还包含支持类型,这些类型有助于管理运行状况事件。

WebBaseErrorEvent 类是表示错误条件的运行状况监视事件的基类。 ASP.NET 使用WebBaseErrorEvent及其派生类型来指示 Web 应用程序的生存期内的错误条件。

备注

在大多数情况下,你将能够使用实现的 ASP.NET 运行状况监视类型,并通过在healthMonitoring配置部分中指定值来控制运行状况监视系统。 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。 有关从 WebBaseErrorEvent 类派生的示例,请参阅本主题中提供的示例。

构造函数

WebBaseErrorEvent(String, Object, Int32, Exception)

初始化 WebBaseErrorEvent 类的新实例。

WebBaseErrorEvent(String, Object, Int32, Int32, Exception)

初始化 WebBaseErrorEvent 类的新实例。

属性

ErrorException

获取与此错误关联的 Exception

EventCode

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

(继承自 WebBaseEvent)
EventDetailCode

获取事件详细信息代码。

(继承自 WebBaseEvent)
EventID

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

(继承自 WebBaseEvent)
EventOccurrence

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

(继承自 WebBaseEvent)
EventSequence

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

(继承自 WebBaseEvent)
EventSource

获取引发事件的对象。

(继承自 WebBaseEvent)
EventTime

获取引发事件的时间。

(继承自 WebBaseEvent)
EventTimeUtc

获取引发事件的时间。

(继承自 WebBaseEvent)
Message

获取描述事件的消息。

(继承自 WebBaseEvent)
ProcessInformation

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

(继承自 WebManagementEvent)

方法

Equals(Object)

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

(继承自 Object)
FormatCustomEventDetails(WebEventFormatter)

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

(继承自 WebBaseEvent)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IncrementPerfCounters()

递增与性能相关的事件-错误计数器。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Raise()

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

(继承自 WebBaseEvent)
ToString()

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

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

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

(继承自 WebBaseEvent)

适用于

另请参阅