WebManagementEvent 类

定义

为带有应用程序和进程信息的事件定义基类。Defines the base class for events that carry application and process information.

public ref class WebManagementEvent : System::Web::Management::WebBaseEvent
public class WebManagementEvent : System.Web.Management.WebBaseEvent
type WebManagementEvent = class
    inherit WebBaseEvent
Public Class WebManagementEvent
Inherits WebBaseEvent
继承
WebManagementEvent
派生

示例

下面的示例演示如何通过从类派生来实现自定义事件 WebManagementEventThe following example shows how to implement a custom event by deriving it from the WebManagementEvent class.


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

namespace Samples.AspNet.Management
{
    // Implements a custom 
    // WebManagementEvent class. 
    public class SampleWebManagementEvent : 
        WebManagementEvent
    {
        private StringBuilder eventInfo;

        // Invoked in case of events 
        // identified only by their event code.
        public SampleWebManagementEvent(string msg, 
            object eventSource, int eventCode):
        base(msg, eventSource, eventCode)
        {
            // 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 SampleWebManagementEvent(string msg, 
            object eventSource, int eventCode, 
            int eventDetailCode):
          base(msg, eventSource, 
            eventCode, eventDetailCode)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
                "Event created at: ", 
                EventTime.ToString()));
        }


        // Raises the SampleWebRequestEvent.
        public override void Raise()
        {
            // Perform custom processing. 
            eventInfo.Append(string.Format(
                "Event raised at: ", 
                EventTime.ToString()));
            // Raise the event.
            base.Raise();
        }

        // Obtains the current process information.
        public string GetProcessInfo()
        {
            StringBuilder tempPi = new StringBuilder();
            WebProcessInformation pi = ProcessInformation;
            tempPi.Append(
                pi.ProcessName + Environment.NewLine);
            tempPi.Append(
                pi.ProcessID.ToString() + Environment.NewLine);
            tempPi.Append(
                pi.AccountName + Environment.NewLine);
            return tempPi.ToString();
        }

        public override void FormatCustomEventDetails(
            WebEventFormatter formatter)
        {
            base.FormatCustomEventDetails(formatter);

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

            formatter.IndentationLevel += 1;
            formatter.AppendLine(
                "** SampleWebManagementEvent Start **");
          
            // Add custom data.
            formatter.AppendLine(eventInfo.ToString());

            formatter.AppendLine(
                      "** SampleWebManagementEvent End **");
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom 
' WebManagementEvent class. 

Public Class SampleWebManagementEvent
   Inherits WebManagementEvent
   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)
        MyBase.New(msg, eventSource, eventCode)
        ' 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 eventDetailCode As Integer)
        MyBase.New(msg, eventSource, _
        eventCode, eventDetailCode)
        ' Perform custom initialization.
        eventInfo = New StringBuilder()
        eventInfo.Append(String.Format( _
        "Event created at: ", EventTime.ToString()))
    End Sub
   
   
   ' Raises the SampleWebRequestEvent.
   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 process information.
   Public Function GetProcessInfo() As String
      Dim tempPi As New StringBuilder()
      Dim pi As WebProcessInformation = ProcessInformation
        tempPi.Append( _
        (pi.ProcessName + Environment.NewLine))
        tempPi.Append( _
        (pi.ProcessID.ToString() + Environment.NewLine))
        tempPi.Append( _
        (pi.AccountName + Environment.NewLine))
      Return tempPi.ToString()
   End Function 'GetProcessInfo
   
   
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter As WebEventFormatter)
        MyBase.FormatCustomEventDetails(formatter)

        ' Add custom data.
        formatter.AppendLine("")

        formatter.IndentationLevel += 1
        formatter.AppendLine( _
        "** SampleWebManagementEvent Start **")

        ' Add custom data.
        formatter.AppendLine(eventInfo.ToString())

        formatter.AppendLine( _
        "** SampleWebManagementEvent End **")
    End Sub
End Class

下面是配置文件的摘录,使 ASP.NET 可以使用自定义事件。The following is an excerpt of the configuration file that enables ASP.NET to use the custom event.

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

    <add  name="SampleWebManagementEvent" type="SamplesAspNet.SampleWebManagementEvent,webmanagementevent,Version=1.0.1573.24438, Culture=neutral, PublicKeyToken=2f5f337ae5c9bdaa, processorArchitecture=MSIL"/>  

  </eventMappings>  
  <rules>  
    <add   
      name="Custom WebManagementEvent"  
      eventName="SampleWebManagementEvent"  
      provider="EventLogProvider"  
      profile="Critical"/>  
  </rules>  
</healthMonitoring>  

注解

ASP.NET health monitoring 允许生产和运营人员管理已部署的 Web 应用程序。ASP.NET health monitoring allows production and operations staff to manage deployed Web applications. System.Web.Management命名空间包含的运行状况事件类型负责打包应用程序运行状况数据,以及负责处理此数据的提供程序类型。The System.Web.Management namespace contains the health-event types responsible for packaging application health-status data and the provider types responsible for processing this data. 它还包含在运行状况事件的管理过程中可帮助的支持类型。It also contains supporting types that help during the management of health events.

WebManagementEvent是所有 ASP.NET health 监视事件类型的基类。The WebManagementEvent is the base class for all the ASP.NET health-monitoring event types. 它使用 WebProcessInformation 类来获取可用于其派生类的进程信息。It uses the WebProcessInformation class to obtain process information that is available to its derived classes.

备注

在大多数情况下,你将能够使用已实现的 ASP.NET health 监视类型,并且将通过在 "配置" 部分中指定值来控制运行状况监视系统 healthMonitoringIn most cases you will be able to use the ASP.NET health-monitoring types as implemented, and you will control the health-monitoring system by specifying values in the healthMonitoring configuration section. 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。You can also derive from the health-monitoring types to create your own custom events and providers. 有关从类派生的示例 WebManagementEvent ,请参阅本主题中提供的示例。For an example of deriving from the WebManagementEvent class, see the example provided in this topic.

继承者说明

格式化要显示的自定义事件信息时,请重写 FormatCustomEventDetails(WebEventFormatter) 方法而不是 ToString 方法。When formatting your custom event information for display, override the FormatCustomEventDetails(WebEventFormatter) method rather than the ToString method. 这将避免覆盖或篡改敏感系统信息。This will avoid overwriting or tampering with sensitive system information.

为自定义事件指定的事件代码必须大于 WebExtendedBaseThe event code you specify for your custom event must be greater than WebExtendedBase.

构造函数

WebManagementEvent(String, Object, Int32)

使用所提供的参数初始化 WebManagementEvent 类的新实例。Initializes a new instance of the WebManagementEvent class using the supplied parameters.

WebManagementEvent(String, Object, Int32, Int32)

使用所提供的参数初始化 WebManagementEvent 类的新实例。Initializes a new instance of the WebManagementEvent class using the supplied parameters.

属性

EventCode

获取与该事件关联的代码值。Gets the code value associated with the event.

(继承自 WebBaseEvent)
EventDetailCode

获取事件详细信息代码。Gets the event detail code.

(继承自 WebBaseEvent)
EventID

获取与事件关联的标识符。Gets the identifier associated with the event.

(继承自 WebBaseEvent)
EventOccurrence

获取表示事件发生次数的计数器。Gets a counter that represents the number of times the event has occurred.

(继承自 WebBaseEvent)
EventSequence

获取应用程序已引发事件的次数。Gets the number of times the event has been raised by the application.

(继承自 WebBaseEvent)
EventSource

获取引发事件的对象。Gets the object that raises the event.

(继承自 WebBaseEvent)
EventTime

获取引发事件的时间。Gets the time when the event was raised.

(继承自 WebBaseEvent)
EventTimeUtc

获取引发事件的时间。Gets the time when the event was raised.

(继承自 WebBaseEvent)
Message

获取描述事件的消息。Gets the message that describes the event.

(继承自 WebBaseEvent)
ProcessInformation

获取有关 ASP.NET 应用程序承载进程的信息。Gets information about the ASP.NET application-hosting process.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FormatCustomEventDetails(WebEventFormatter)

提供事件信息的标准格式设置。Provides standard formatting of the event information.

(继承自 WebBaseEvent)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IncrementPerfCounters()

在内部使用,用于递增性能计数器。Used internally to increment performance counters.

(继承自 WebBaseEvent)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Raise()

通过将事件已发生这一情况通知任何已配置的提供程序来引发事件。Raises an event by notifying any configured provider that the event has occurred.

(继承自 WebBaseEvent)
ToString()

为显示而对事件信息进行格式化。Formats event information for display purposes.

(继承自 WebBaseEvent)
ToString(Boolean, Boolean)

为显示而对事件信息进行格式化。Formats event information for display purposes.

(继承自 WebBaseEvent)

适用于

另请参阅