WebApplicationInformation 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供与状况事件相关的信息。
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() |
为显示而对事件信息进行格式化。 |