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)

適用於

另請參閱