語言

WebErrorEvent 類別

定義

提供有關系統性錯誤的資訊。

public ref class WebErrorEvent : System::Web::Management::WebBaseErrorEvent
public class WebErrorEvent : System.Web.Management.WebBaseErrorEvent
type WebErrorEvent = class
    inherit WebBaseErrorEvent
Public Class WebErrorEvent
Inherits WebBaseErrorEvent
繼承

範例

以下程式碼範例說明如何從 WebErrorEvent 類別衍生出自訂事件。

同時展示一段設定檔摘錄,讓 ASP.NET 能使用此自訂事件。

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

  <eventMappings>

    <add  name="SampleWebErrorEvent" type="SamplesAspNet.SampleWebErrorEvent,weberrorevent,Version=1.0.1573.21549, Culture=neutral, PublicKeyToken=2a0b23915ac7352b, processorArchitecture=MSIL"/>

  </eventMappings>

  <profiles>
    <add name="Custom"
      minInstances="1"
      maxLimit="Infinite"
      minInterval="00:00:00" />
  </profiles>

  <rules>
    <clear />

    <add name="Custom Web Error Event"
      eventName="SampleWebErrorEvent"
      provider="EventLogProvider"
      profile="Custom" />
  </rules>

</healthMonitoring>

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 健康監控讓生產與營運人員能管理已部署的網頁應用程式。 System.Web.Management命名空間包含負責包裝應用程式健康狀態資料的健康事件類型,以及負責處理這些資料的提供者類型。 同時也包含協助健康事件管理的支援類型。

它 WebErrorEvent 提供因設定或應用程式碼問題所導致錯誤的資訊。 例如,當頁面中發現錯誤時,ASP.NET 會發出錯誤。

Note

大多數情況下,你可以依實作使用 ASP.NET 健康監控類型,並且透過在 healthMonitoring 配置區塊指定數值來控制健康監控系統。 你也可以從健康監控類型中衍生,建立屬於自己的活動和服務提供者。 關於從該 WebErrorEvent 類別推導的範例,請參見本主題中的範例。

建構函式

名稱 Description
WebErrorEvent(String, Object, Int32, Exception)

使用提供的參數初始化類別 WebErrorEvent 。

WebErrorEvent(String, Object, Int32, Int32, Exception)

使用所提供的參數初始化該類別的新實例 WebErrorEvent 。

屬性

名稱 Description
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

取得應用程式執行緒的資訊。

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FormatCustomEventDetails(WebEventFormatter)

提供活動資訊的標準格式。

(繼承來源 WebBaseEvent)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
IncrementPerfCounters()

內部用來增加效能計數器。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Raise()

透過通知任何已設定的提供者事件已發生,從而提出事件。

(繼承來源 WebBaseEvent)
ToString()

格式化活動資訊以供展示用途。

(繼承來源 WebBaseEvent)
ToString(Boolean, Boolean)

格式化活動資訊以供展示用途。

(繼承來源 WebBaseEvent)

適用於

另請參閱