WebProcessInformation 類別

定義

提供裝載 ASP.NET 之背景工作處理序的相關資訊。

public ref class WebProcessInformation sealed
public sealed class WebProcessInformation
type WebProcessInformation = class
Public NotInheritable Class WebProcessInformation
繼承
WebProcessInformation

範例

下列範例有兩個部分。 第一個是組態檔的摘錄,可讓 ASP.NET 使用使用 類型的 WebProcessInformation 自訂事件。

第二個示範如何實作自訂事件。

請確定您的自訂事件會在適當的時間引發,也就是說,當相等的系統健康情況事件引發時,就會引發它所取代的事件。

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

    <eventMappings>  
      <add    
        name="SampleProcessInformation"   
        type="SamplesAspNet.SampleWebProcessInformation, webprocessinformation, Version=1.0.1585.27289, Culture=neutral, PublicKeyToken=3648e5c763a8239f, processorArchitecture=MSIL"/>  
    </eventMappings>  

    <rules>  
      <add   
        name="Custom Process Information"  
        eventName="SampleProcessInformation"   
        provider="EventLogProvider"  
        profile="Default"/>  
    </rules>  

</healthMonitoring>  

下列範例示範如何實作使用 型別的 WebProcessInformation 自訂事件。


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

namespace SamplesAspNet
{
    // Implements a custom WebBaseEvent type that 
    // uses WebProcessInformation.
    public class SampleWebProcessInformation: 
        WebManagementEvent
    {
        private StringBuilder eventInfo;
        // Instantiate SampleWebProcessInformation.    
        public SampleWebProcessInformation(string msg, 
            object eventSource, int eventCode) : 
        base(msg, eventSource, eventCode)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
            "Event created at: {0}", 
            EventTime.ToString()));
        }   

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

            // Raise the event.
            base.Raise();
        }

        public string GetAccountName()
        {
            // Get the name of the account.
            return (string.Format(
                "Account name: {0}", 
                ProcessInformation.AccountName));
        }

        public string GetProcessId()
        {
            // Get the process identifier.
            return (string.Format(
                "Process Id: {0}", 
                ProcessInformation.ProcessID.ToString()));
        }

        public string GetProcessName()
        {
            // Get the requests in execution.
            return (string.Format(
                "Process name: {0}", 
                ProcessInformation.ProcessName));
        }

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

            // Add custom data.
            formatter.AppendLine("Custom Process Information:");
            formatter.IndentationLevel += 1;

            // Display the process information.
            formatter.AppendLine(GetAccountName());
            formatter.AppendLine(GetProcessId());
            formatter.AppendLine(GetProcessName());
            formatter.IndentationLevel -= 1;
            formatter.AppendLine(eventInfo.ToString());
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebBaseEvent type that 
' uses WebProcessInformation.

Public Class SampleWebProcessInformation
   Inherits WebBaseEvent
   Private eventInfo As StringBuilder
    Private Shared processInformation _
    As WebProcessInformation
   
   ' Instantiate SampleWebProcessInformation.    
    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: {0}", _
        EventTime.ToString()))

    End Sub
   
   ' Raises the event.
   Public Overrides Sub Raise()
      ' Perform custom processing. 
        eventInfo.Append(String.Format( _
        "Event raised at: {0}", _
        EventTime.ToString()))
      
      ' Raise the event.
      MyBase.Raise()
   End Sub
   
   Public Function GetAccountName() As String
      ' Get the name of the account.
        Return String.Format("Account name: {0}", _
        processInformation.AccountName)
   End Function 'GetAccountName
   
   Public Function GetProcessId() As String
      ' Get the process identifier.
        Return String.Format("Process Id: {0}", _
        processInformation.ProcessID.ToString())
   End Function 'GetProcessId
   
   Public Function GetProcessName() As String
      ' Get the requests in execution.
        Return String.Format("Process name: {0}", _
        ProcessInformation.ProcessName)
   End Function 'GetProcessName
   
    'Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter _
    As System.Web.Management.WebEventFormatter)
        MyBase.FormatCustomEventDetails(formatter)
   
        ' Add custom data.
        formatter.AppendLine("")
        formatter.AppendLine( _
        "Custom Process Information:")
        formatter.IndentationLevel += 1

        ' Display the process information.
        formatter.AppendLine(GetAccountName())
        formatter.AppendLine(GetProcessId())
        formatter.AppendLine(GetProcessName())
        formatter.IndentationLevel -= 1
        formatter.AppendLine(eventInfo.ToString())
    End Sub

End Class

備註

ASP.NET 健康情況監視可讓生產與作業人員管理已部署的 Web 應用程式。 System.Web.Management命名空間包含負責封裝應用程式健康狀態資料的健全狀況事件種類,以及負責處理此資料的提供者類型。 它也包含支援類型,可協助管理健康情況事件。

類別的 WebProcessInformation 實例包含使用衍生自 WebManagementEvent 型別的任何類型取得的資訊。

您的應用程式需要適當的許可權,才能存取此類型所提供的受保護資訊。

下列範例是組態檔的摘錄,可用來啟用 ASP.NET 來記錄包含進程資訊的錯誤事件。

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

    <rules>  
     <add   
       name="All Errors Default"  
       eventName="All Errors"  
       provider="EventLogProvider"  
       profile="Default"  
       minInterval="00:01:00" />  
    </rules>  

</healthMonitoring>  

注意

在大部分情況下,您將能夠使用實作的 ASP.NET 健康情況監視類型,而且您會在組態區段中指定值 healthMonitoring 來控制健康情況監視系統。 您也可以衍生自健康情況監視類型,以建立您自己的自訂事件和提供者。 如需建立自訂事件類別的範例,請參閱範例一節。

屬性

AccountName

取得背景工作處理序的帳戶名稱。

ProcessID

取得處理序識別項。

ProcessName

取得處理序的名稱。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FormatToString(WebEventFormatter)

格式化應用程式資訊。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱