共用方式為


WebApplicationInformation 類別

定義

提供與健康事件關聯的資訊。

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

範例

下列程式碼範例有兩個部分。 第一個部分是組態檔的摘錄,可讓 ASP.NET 使用自訂事件。 第二個示範如何使用 類別建立該自訂事件 WebApplicationInformation

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

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

  <eventMappings>   
    <add name="SampleApplicationInformation"   
        type="SamplesAspNet.SampleWebApplicationInformation, webapplicationinformation, Version=1.0.1585.27289, Culture=neutral, PublicKeyToken=3648e5c763a8239f, processorArchitecture=MSIL"/>   
  </eventMappings>  

  <rules>   
    <add name="Custom Application Information"  
      eventName="SampleApplicationInformation"   
      provider="EventLogProvider"    
      profile="Default"/>   
</rules>  

</healthMonitoring>  
using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebBaseEvent that uses
    // WebApplicationInformation.
    public class SampleWebApplicationInformation :
        WebBaseEvent
    {
        private StringBuilder eventInfo;

        // Instantiate SampleWebGet    
        public SampleWebApplicationInformation(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 GetApplicationDomain()
        {
            // Get the name of the application domain.
            return (string.Format(
                "Application domain: {0}",
                ApplicationInformation.ApplicationDomain));
        }
        public string GetApplicationPath()
        {
            // Get the name of the application  path.
            return (string.Format(
                "Application path: {0}",
                ApplicationInformation.ApplicationPath));
        }
        public string GetApplicationVirtualPath()
        {
            // Get the name of the application virtual path.
            return (string.Format(
                "Application virtual path: {0}",
                ApplicationInformation.ApplicationVirtualPath));
        }
        public string GetApplicationMachineName()
        {
            // Get the name of the application machine name.
            return (string.Format(
                "Application machine name: {0}",
                ApplicationInformation.MachineName));
        }
        public string GetApplicationTrustLevel()
        {
            // Get the name of the application trust level.
            return (string.Format(
                "Application trust level: {0}",
                ApplicationInformation.TrustLevel));
        }
        //Formats Web request event information.
        public override void FormatCustomEventDetails(
            WebEventFormatter formatter)
        {
            base.FormatCustomEventDetails(formatter);

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

            // Display the application information.
            formatter.AppendLine(GetApplicationDomain());
            formatter.AppendLine(GetApplicationPath());
            formatter.AppendLine(GetApplicationVirtualPath());
            formatter.AppendLine(GetApplicationMachineName());
            formatter.AppendLine(GetApplicationTrustLevel());
            formatter.IndentationLevel -= 1;
            formatter.AppendLine(eventInfo.ToString());
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


'Implements a custom WebBaseEvent that uses
' WebApplicationInformation. 
Public Class SampleWebApplicationInformation
    Inherits WebBaseEvent
    Private eventInfo As StringBuilder


    ' Instantiate SampleWebGet    
    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 GetApplicationDomain() As String
        ' Get the name of the application domain.
        Return String.Format( _
        "Application domain: {0}", _
        ApplicationInformation.ApplicationDomain)
    End Function 'GetApplicationDomain

    Public Function GetApplicationPath() As String
        ' Get the name of the application  path.
        Return String.Format( _
        "Application path: {0}", _
        ApplicationInformation.ApplicationPath())
    End Function 'GetApplicationPath

    Public Function GetApplicationVirtualPath() As String
        ' Get the name of the application virtual path.
        Return String.Format( _
        "Application virtual path: {0}", _
        ApplicationInformation.ApplicationVirtualPath())
    End Function 'GetApplicationVirtualPath

    Public Function GetApplicationMachineName() As String
        ' Get the name of the application machine name.
        Return String.Format( _
        "Application machine name: {0}", _
        ApplicationInformation.MachineName())
    End Function 'GetApplicationMachineName

    Public Function GetApplicationTrustLevel() As String
        ' Get the name of the application trust level.
        Return String.Format( _
        "Application trust level: {0}", _
        ApplicationInformation.TrustLevel())
    End Function 'GetApplicationTrustLevel

    'Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
 _
     ByVal formatter As WebEventFormatter)
        MyBase.FormatCustomEventDetails(formatter)

        ' Add custom data.
        formatter.AppendLine( _
        "Custom Application Information:")
        formatter.IndentationLevel += 1

        ' Display the application information.
        formatter.AppendLine(GetApplicationDomain())
        formatter.AppendLine(GetApplicationPath())
        formatter.AppendLine(GetApplicationVirtualPath())
        formatter.AppendLine(GetApplicationMachineName())
        formatter.AppendLine(GetApplicationTrustLevel())
        formatter.IndentationLevel -= 1
        formatter.AppendLine(eventInfo.ToString())
    End Sub
End Class

備註

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

類別的 WebApplicationInformation 實例包含使用衍生自 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 來控制健康情況監視系統。 您也可以衍生自健康情況監視類型,以建立您自己的自訂事件和提供者。 如需建立自訂事件類別的範例,請參閱本主題中提供的範例。

屬性

ApplicationDomain

取得目前應用程式定義域名稱。

ApplicationPath

取得應用程式實體路徑。

ApplicationVirtualPath

取得應用程式邏輯路徑。

MachineName

取得應用程式電腦名稱。

TrustLevel

取得應用程式信任層級。

方法

Equals(Object)

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

(繼承來源 Object)
FormatToString(WebEventFormatter)

格式化應用程式資訊。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

針對顯示用途,格式化事件資訊。

適用於

另請參閱