次の方法で共有


WebApplicationLifetimeEvent クラス

定義

アプリケーションの有効期間中に発生した重要なイベントを表します。

public ref class WebApplicationLifetimeEvent : System::Web::Management::WebManagementEvent
public class WebApplicationLifetimeEvent : System.Web.Management.WebManagementEvent
type WebApplicationLifetimeEvent = class
    inherit WebManagementEvent
Public Class WebApplicationLifetimeEvent
Inherits WebManagementEvent
継承
WebApplicationLifetimeEvent

次のコード例は、 クラスから WebApplicationLifetimeEvent 派生してカスタム イベントを作成する方法を示しています。


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

namespace SamplesAspNet
{
  // Implements a custom WebManagementEvent class. 
    public class SampleWebApplicationLifetimeEvent :
        System.Web.Management.WebApplicationLifetimeEvent
    {
        private string customCreatedMsg, customRaisedMsg;

        // Invoked in case of events identified only by 
        // their event code.
        public SampleWebApplicationLifetimeEvent(string msg, 
            object eventSource, int eventCode):
          base(msg, eventSource, eventCode)
        {
            // Perform custom initialization.
            customCreatedMsg =
            string.Format("Event created at: {0}",
            DateTime.Now.TimeOfDay.ToString());
        }

        // Invoked in case of events identified by their 
        // event code.and related event detailed code.
        public SampleWebApplicationLifetimeEvent(string msg, 
            object eventSource, int eventCode, 
            int eventDetailCode):
          base(msg, eventSource, eventCode, eventDetailCode)
        {
            // Perform custom initialization.
            customCreatedMsg =
             string.Format("Event created at: {0}",
             DateTime.Now.TimeOfDay.ToString());
        }


        // Raises the SampleWebRequestEvent.
        public override void Raise()
        {
            // Perform custom processing. 
            customRaisedMsg = string.Format(
                "Event raised at: {0}\n", 
                DateTime.Now.TimeOfDay.ToString());
            // Raise the event.
            base.Raise();
        }

        //Formats Web request event information.
        public override void FormatCustomEventDetails(
            WebEventFormatter formatter)
        {
            base.FormatCustomEventDetails(formatter);

            // Add custom data.
            formatter.AppendLine("");

            formatter.IndentationLevel += 1;
    
            formatter.TabSize = 4;
       
            formatter.AppendLine(
                 "*SampleWebApplicationLifetimeEvent Start *");
            formatter.AppendLine("Custom information goes here");
            formatter.AppendLine(
                "* SampleWebApplicationLifetimeEvent End *");
            // Display custom event timing.
            formatter.AppendLine(customCreatedMsg);
            formatter.AppendLine(customRaisedMsg);
        
            formatter.IndentationLevel -= 1;
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebManagementEvent class. 

Public Class SampleWebApplicationLifetimeEvent
    Inherits System.Web.Management.WebApplicationLifetimeEvent
    Private customCreatedMsg, customRaisedMsg As String
    
    ' 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)
        MyBase.New(msg, eventSource, eventCode)
        ' Perform custom initialization.
        customCreatedMsg = _
        String.Format("Event created at: {0}", _
        DateTime.Now.TimeOfDay.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 eventDetailCode As Integer)
        MyBase.New(msg, eventSource, _
        eventCode, eventDetailCode)
        ' Perform custom initialization.
        customCreatedMsg = _
        String.Format("Event created at: {0}", _
        DateTime.Now.TimeOfDay.ToString())
    End Sub


    ' Raises the SampleWebRequestEvent.
    Public Overrides Sub Raise() 
        ' Perform custom processing. 
        customRaisedMsg = _
        String.Format("Event raised at: {0}" + _
        vbLf, DateTime.Now.TimeOfDay.ToString())
        ' Raise the event.
        MyBase.Raise()
    
    End Sub
    
    '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.TabSize = 4

        formatter.AppendLine( _
        "*SampleWebApplicationLifetimeEvent Start *")
        formatter.AppendLine("Custom information goes here")
        formatter.AppendLine( _
        "* SampleWebApplicationLifetimeEvent End *")
        ' Display custom event timing.
        formatter.AppendLine(customCreatedMsg)
        formatter.AppendLine(customRaisedMsg)

        formatter.IndentationLevel -= 1

    End Sub
End Class

次の構成ファイルの抜粋は、構成ファイルのセクションを healthMonitoring 構成して、上記で定義したコードを SampleWebApplicationLifetimeEvent ASP.NET の正常性監視システムに追加する方法を示しています。 システムにイベントを追加するには、セクションに新しいエントリを追加してイベントを eventMappings 定義し、新しいエントリをセクションに追加してイベントをプロバイダーにマップする rules 必要があります。

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

    <eventMappings>  
       <clear />  
       <!-- Configure the application lifetime event -->  
       <!-- object to handle the Web application events. -->  
       <add name="SampleApplicationLifetimeEvents"  
         type="System.Web.Management.SampleWebApplicationLifetimeEvent,  
         System.Web,Version=2.0.3600.0,  
         Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />  
     </eventMappings>  

    <rules>  
      <clear/>  
       // Configure the connection between the   
       // application lifetime event object   
       // and the provider that must process it.  
       <add name="Custom Application Events"  
         eventName="SampleApplicationLifetimeEvents"  
         provider="EventLogProvider"  
         profile="Default"  
         minInterval="00:01:00" />  
    </rules>  

</healthMonitoring>  

注釈

ASP.NET 正常性の監視により、運用スタッフと運用スタッフはデプロイされた Web アプリケーションを管理できます。 System.Web.Management名前空間には、アプリケーションの正常性状態データのパッケージ化を担当する正常性イベントの種類と、このデータの処理を担当するプロバイダーの種類が含まれています。 また、正常性イベントの管理中に役立つサポート型も含まれています。

アプリケーションの有効期間イベントには、アプリケーションの起動イベントやシャットダウン イベントなどのイベントが含まれます。 アプリケーションが終了した場合は、関連するイベント メッセージ フィールドを表示して理由を判断できます。

インスタンスが WebApplicationLifetimeEvent 発生すると、正常性監視 ASP.NET アプリケーションの有効期間イベントのパフォーマンス カウンターが更新されます。 これらのイベントをログに記録するには、次の例にrules示すように、 オブジェクトをhealthMonitoring構成ファイルの セクションのサブセクションに追加WebApplicationLifetimeEventします。

<rules>  
  <add name="Application Events"  
    eventName="Application Lifetime Events"  
    provider="EventLogProvider"  
    profile="Default"  
    minInterval="00:01:00" />  
</rules>  

Application Lifetime Events パフォーマンス カウンターには、すべての ASP.NET 有効期間イベントの合計が含まれます。 このパフォーマンス カウンターをシステム モニター (PerfMon) で表示するには、[カウンターの追加] ウィンドウで、[パフォーマンス オブジェクト] ドロップダウン リストから [ASP.NET] を選択します。 [ アプリケーション有効期間イベント ] パフォーマンス カウンターを選択し、[ 追加 ] ボタンをクリックします。 詳細については、MSDN の「ASP.NET アプリケーションでのシステム モニター (PerfMon) の使用」を参照 してください。 標準EventLogWebEventProviderでイベントをログに記録できるようにする場合は、アプリケーション ログを選択してイベント ビューアーでイベントを表示できます。

注意事項

オブジェクトは大量の WebApplicationLifetimeEvent イベントであるため、ログ記録はリソースを集中的に消費し、システムの速度が低下する可能性があります。 また、イベントの量が多く、イベント ログの動作方法が原因で、 クラスの EventLogWebEventProvider 場合に他のイベントが上書きされる可能性もあります。

注意

ほとんどの場合、実装されている ASP.NET の正常性監視の種類を使用でき、構成セクションで値を指定して正常性監視システムを healthMonitoring 制御します。 正常性監視の種類から派生して、独自のカスタム イベントとプロバイダーを作成することもできます。 クラスから WebApplicationLifetimeEvent 派生する例については、このトピックで提供される例を参照してください。

注意 (継承者)

カスタム イベント情報を表示用に書式設定する場合は、 メソッドではなく メソッドをFormatCustomEventDetails(WebEventFormatter)ToStringオーバーライドします。 これにより、機密性の高いシステム情報の上書きや改ざんを回避できます。

コンストラクター

WebApplicationLifetimeEvent(String, Object, Int32)

指定されたパラメーターを使用して WebApplicationLifetimeEvent クラスを初期化します。

WebApplicationLifetimeEvent(String, Object, Int32, Int32)

指定されたパラメーターを使用して WebApplicationLifetimeEvent クラスを初期化します。

プロパティ

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)

適用対象

こちらもご覧ください