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

次のコード例には、2 つの部分があります。 最初の部分は、ASP.NET がカスタム イベントを使用できるようにする構成ファイルの抜粋です。 2 番目の部分では、 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 クラスで定義されている要求関連の情報を取得する必要があります。

Note

ほとんどの場合、標準の 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)

適用対象

こちらもご覧ください