WebErrorEvent 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供有关系统错误的信息。
public ref class WebErrorEvent : System::Web::Management::WebBaseErrorEvent
public class WebErrorEvent : System.Web.Management.WebBaseErrorEvent
type WebErrorEvent = class
inherit WebBaseErrorEvent
Public Class WebErrorEvent
Inherits WebBaseErrorEvent
- 继承
示例
下面的代码示例演示如何派生自 WebErrorEvent 类以创建自定义事件。
此外,还显示了配置文件的摘录,使 ASP.NET 能够使用此自定义事件。
<healthMonitoring
enabled="true" heartBeatInterval="0">
<eventMappings>
<add name="SampleWebErrorEvent" type="SamplesAspNet.SampleWebErrorEvent,weberrorevent,Version=1.0.1573.21549, Culture=neutral, PublicKeyToken=2a0b23915ac7352b, processorArchitecture=MSIL"/>
</eventMappings>
<profiles>
<add name="Custom"
minInstances="1"
maxLimit="Infinite"
minInterval="00:00:00" />
</profiles>
<rules>
<clear />
<add name="Custom Web Error Event"
eventName="SampleWebErrorEvent"
provider="EventLogProvider"
profile="Custom" />
</rules>
</healthMonitoring>
using System;
using System.Text;
using System.Web;
using System.Web.Management;
namespace Samples.AspNet.Management
{
// Implements a custom WebErrorEvent class.
public class SampleWebErrorEvent : WebErrorEvent
{
private StringBuilder eventInfo;
// Invoked in case of events identified
// only by their event code.
public SampleWebErrorEvent(string msg,
object eventSource, int eventCode, Exception e)
:
base(msg, eventSource, eventCode, e)
{
// 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 SampleWebErrorEvent(string msg,
object eventSource, int eventCode,
int detailedCode, Exception e):
base(msg, eventSource,
eventCode, detailedCode, e)
{
// Perform custom initialization.
eventInfo = new StringBuilder();
eventInfo.Append(string.Format(
"Event created at: ", EventTime.ToString()));
}
// Raises the SampleWebErrorEvent.
public override void Raise()
{
// Perform custom processing.
eventInfo.Append(string.Format(
"Event raised at: ", EventTime.ToString()));
// Raise the event.
base.Raise();
}
// Obtains the current request information.
public string GetRequestInfo()
{
string reqInfo = GetRequestInfo();
return reqInfo;
}
// Obtains the current thread information.
public string GetThreadInfo()
{
string threadInfo = GetThreadInfo();
return threadInfo;
}
// Obtains the current process information.
public string GetProcessInfo()
{
string procInfo = GetProcessInfo();
return procInfo;
}
//Formats Web request event information..
public override void FormatCustomEventDetails(
WebEventFormatter formatter)
{
base.FormatCustomEventDetails(formatter);
// Add custom data.
formatter.AppendLine("");
formatter.IndentationLevel += 1;
formatter.AppendLine(
"** SampleWebErrorEvent Start **");
formatter.AppendLine(eventInfo.ToString());
formatter.AppendLine(
"** SampleWebBaseErrorEvent End **");
formatter.IndentationLevel -= 1;
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
' Implements a custom WebErrorEvent class.
Public Class SampleWebErrorEvent
Inherits WebErrorEvent
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, ByVal e As Exception)
MyBase.New(msg, eventSource, eventCode, e)
' 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 detailedCode As Integer, ByVal e As Exception)
MyBase.New(msg, eventSource, _
eventCode, detailedCode, e)
' Perform custom initialization.
eventInfo = New StringBuilder()
eventInfo.Append(String.Format( _
"Event created at: ", EventTime.ToString()))
End Sub
' Raises the SampleWebErrorEvent.
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 request information.
Public Function GetRequestInfo() As String
Dim reqInfo As String = GetRequestInfo()
Return reqInfo
End Function 'GetRequestInfo
' Obtains the current thread information.
Public Function GetThreadInfo() As String
Dim threadInfo As String = GetThreadInfo()
Return threadInfo
End Function 'GetThreadInfo
' Obtains the current process information.
Public Function GetProcessInfo() As String
Dim procInfo As String = GetProcessInfo()
Return procInfo
End Function 'GetProcessInfo
'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.AppendLine( _
"** SampleWebErrorEvent Start **")
formatter.AppendLine(eventInfo.ToString())
formatter.AppendLine( _
"** SampleWebBaseErrorEvent End **")
formatter.IndentationLevel -= 1
End Sub
End Class
注解
ASP.NET 运行状况监视允许生产和运营人员管理已部署的 Web 应用程序。 命名空间 System.Web.Management 包含负责打包应用程序运行状况状态数据的运行状况事件类型和负责处理此数据的提供程序类型。 它还包含支持类型,这些类型有助于管理运行状况事件。
提供有关 WebErrorEvent 配置或应用程序代码问题导致的错误的信息。 例如,在页面上找到错误时,ASP.NET 发出的错误。
备注
在大多数情况下,你将能够使用实现的 ASP.NET 运行状况监视类型,并通过在healthMonitoring配置部分中指定值来控制运行状况监视系统。 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。 有关从 WebErrorEvent 类派生的示例,请参阅本主题中提供的示例。
构造函数
| WebErrorEvent(String, Object, Int32, Exception) |
使用所提供的参数初始化 WebErrorEvent 类。 |
| WebErrorEvent(String, Object, Int32, Int32, Exception) |
使用所提供的参数初始化 WebErrorEvent 类的新实例。 |
属性
| ErrorException |
获取与此错误关联的 Exception。 (继承自 WebBaseErrorEvent) |
| EventCode |
获取与该事件关联的代码值。 (继承自 WebBaseEvent) |
| EventDetailCode |
获取事件详细信息代码。 (继承自 WebBaseEvent) |
| EventID |
获取与事件关联的标识符。 (继承自 WebBaseEvent) |
| EventOccurrence |
获取表示事件发生次数的计数器。 (继承自 WebBaseEvent) |
| EventSequence |
获取应用程序已引发事件的次数。 (继承自 WebBaseEvent) |
| EventSource |
获取引发事件的对象。 (继承自 WebBaseEvent) |
| EventTime |
获取引发事件的时间。 (继承自 WebBaseEvent) |
| EventTimeUtc |
获取引发事件的时间。 (继承自 WebBaseEvent) |
| Message |
获取描述事件的消息。 (继承自 WebBaseEvent) |
| ProcessInformation |
获取有关 ASP.NET 应用程序承载进程的信息。 (继承自 WebManagementEvent) |
| RequestInformation |
获取应用程序请求信息。 |
| ThreadInformation |
获取应用程序线程信息。 |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
| FormatCustomEventDetails(WebEventFormatter) |
提供事件信息的标准格式设置。 (继承自 WebBaseEvent) |
| GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IncrementPerfCounters() |
在内部使用,用于递增性能计数器。 |
| MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
| Raise() |
通过将事件已发生这一情况通知任何已配置的提供程序来引发事件。 (继承自 WebBaseEvent) |
| ToString() |
为显示而对事件信息进行格式化。 (继承自 WebBaseEvent) |
| ToString(Boolean, Boolean) |
为显示而对事件信息进行格式化。 (继承自 WebBaseEvent) |