共用方式為


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 健全狀況監視會更新應用程式存留期事件效能計數器。 您可以將 物件新增 WebApplicationLifetimeEventrules 組態檔區段的 healthMonitoring 子區段,以記錄這些事件,如下列範例所示。

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

應用程式存留期事件效能計數器包含所有 ASP.NET 存留期事件的總和。 若要在 [系統監視器] (PerfMon) 中檢視此效能計數器,請在 [新增計數器] 視窗中,從 [效能物件] 下拉式清單中選取 [ASP.NET]。 選取 [應用程式存留期事件] 效能計數器,然後按一下 [ 新增 ] 按鈕。 For more information, see "Using the System Monitor (PerfMon) with ASP.NET Applications" on MSDN. 如果您允許由標準 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)

適用於

另請參閱