WebApplicationLifetimeEvent 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示应用程序的生存期中重要的事件。
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 类派生以创建自定义事件。
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 运行状况监视更新应用程序生存期事件性能计数器。 可以通过将 WebApplicationLifetimeEvent 对象添加到 rules 配置文件的 节的 healthMonitoring 子节来记录这些事件,如以下示例所示。
<rules>  
  <add name="Application Events"  
    eventName="Application Lifetime Events"  
    provider="EventLogProvider"  
    profile="Default"  
    minInterval="00:01:00" />  
</rules>  
应用程序生存期事件性能计数器包含所有 ASP.NET 生存期事件的总和。 若要在系统监视器 (PerfMon) 中查看此性能计数器,请在“添加计数器”窗口中从“性能对象”下拉列表中选择 ASP.NET。 选择 “应用程序生存期事件” 性能计数器,然后单击“ 添加 ”按钮。 有关详细信息,请参阅 MSDN 上的“将系统监视器 (PerfMon) 与 ASP.NET 应用程序配合使用”。 如果允许标准 EventLogWebEventProvider记录事件,可以通过选择应用程序日志在事件查看器中查看它们。
注意
由于对象 WebApplicationLifetimeEvent 是大量事件,因此记录该对象会占用大量资源,并且可能会降低系统速度。 在 类的情况下 EventLogWebEventProvider ,它还可能导致其他事件被覆盖,因为事件量很大,并且事件日志记录的工作方式也很大。
注意
在大多数情况下,你将能够使用 ASP.NET 实现的运行状况监视类型,并通过在配置节中 healthMonitoring 指定值来控制运行状况监视系统。 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。 有关从 WebApplicationLifetimeEvent 类派生的示例,请参阅本主题中提供的示例。
继承者说明
设置自定义事件信息的格式以供显示时,请重写 FormatCustomEventDetails(WebEventFormatter) 方法,而不是 ToString 方法。 这将避免覆盖或篡改敏感系统信息。
构造函数
| WebApplicationLifetimeEvent(String, Object, Int32, Int32) | 
		 使用所提供的参数初始化 WebApplicationLifetimeEvent 类。  | 
        	
| WebApplicationLifetimeEvent(String, Object, 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) |