WebBaseEventCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含 WebBaseEvent 对象的集合。 此类不能被继承。
public ref class WebBaseEventCollection sealed : System::Collections::ReadOnlyCollectionBase
public sealed class WebBaseEventCollection : System.Collections.ReadOnlyCollectionBase
type WebBaseEventCollection = class
inherit ReadOnlyCollectionBase
Public NotInheritable Class WebBaseEventCollection
Inherits ReadOnlyCollectionBase
- 继承
示例
下面的代码示例演示如何使用 WebBaseEventCollection 类。
using System;
using System.Text;
using System.Web;
using System.Web.Management;
using System.Collections;
namespace SamplesAspNet
{
// Implements a custom WebBaseEvent class.
// Everytime this class is instantiated a WebBaseEvent is
// created. This event object is then added to the static
// simulatedEvents array list.
public class SampleWebBaseEventCollection : System.Web.Management.WebBaseEvent
{
private string customCreatedMsg;
private static ArrayList simulatedEvents = new ArrayList();
private static System.Web.Management.WebBaseEventCollection events;
// Create a new WebBaseEvent and add it to the
// static array list simulatedEvents.
public SampleWebBaseEventCollection(
string msg, object eventSource, int eventCode):
base(msg, eventSource, eventCode)
{
customCreatedMsg =
string.Format("Event created at: {0}",
DateTime.Now.TimeOfDay.ToString());
simulatedEvents.Add(this);
}
// Get the event with the specified index.
public static WebBaseEvent GetItem(int index)
{
return events[index];
}
// Get the index of the specified event.
public static int GetIndexOf(WebBaseEvent ev)
{
return events.IndexOf(ev);
}
// Check if the specified event is in the collection.
public static bool ContainsEvent(WebBaseEvent ev)
{
return events.Contains(ev);
}
// Create an event collection.
// Add to it the created simulatedEvents.
public static void AddEvents()
{
events =
new System.Web.Management.WebBaseEventCollection(
simulatedEvents);
}
// Display the events contained in the collection.
public override void FormatCustomEventDetails(WebEventFormatter formatter)
{
base.FormatCustomEventDetails(formatter);
// Add custom data.
formatter.AppendLine("");
formatter.IndentationLevel += 1;
formatter.AppendLine(
"**SampleWebBaseEventCollection Data Start **");
foreach (WebBaseEvent ev in events)
{
formatter.AppendLine(string.Format(
"Message: {0}", ev.Message));
formatter.AppendLine(string.Format(
"Source: {0}", ev.EventSource.ToString()));
formatter.AppendLine(string.Format(
"Code: {0}", ev.EventCode.ToString()));
}
formatter.AppendLine(
"**SampleWebBaseEventCollection Data End **");
formatter.IndentationLevel -= 1;
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
Imports System.Collections
' Implements a custom WebBaseEvent class.
' Everytime this class is instantiated a WebBaseEvent is
' created. This event object is then added to the static
' simulatedEvents array list.
Public Class SampleWebBaseEventCollection
Inherits System.Web.Management.WebBaseEvent
Private customCreatedMsg As String
Private Shared simulatedEvents As New ArrayList()
Private Shared events _
As System.Web.Management.WebBaseEventCollection
' Create a new WebBaseEvent and add it to the
' static array list simulatedEvents.
Public Sub New(ByVal msg As String, ByVal eventSource As Object, _
ByVal eventCode As Integer)
MyBase.New(msg, eventSource, eventCode)
customCreatedMsg = String.Format("Event created at: {0}", _
DateTime.Now.TimeOfDay.ToString())
simulatedEvents.Add(Me)
End Sub
' Get the event with the specified index.
Public Shared Function GetItem(ByVal index _
As Integer) As WebBaseEvent
Return events(index)
End Function 'GetItem
' Get the index of the specified event.
Public Shared Function GetIndexOf(ByVal ev _
As WebBaseEvent) As Integer
Return events.IndexOf(ev)
End Function 'GetIndexOf
' Chek if the specified event is in the collection.
Public Shared Function ContainsEvent(ByVal ev _
As WebBaseEvent) As Boolean
Return events.Contains(ev)
End Function 'ContainsEvent
' Create an event collection.
' Add to it the created simulatedEvents.
Public Shared Sub AddEvents()
events = _
New System.Web.Management.WebBaseEventCollection(simulatedEvents)
End Sub
' Display the events contained in the collection.
Public Overrides Sub FormatCustomEventDetails(ByVal formatter _
As WebEventFormatter)
MyBase.FormatCustomEventDetails(formatter)
' Add custom data.
formatter.AppendLine("")
formatter.IndentationLevel += 1
formatter.AppendLine("**SampleWebBaseEventCollection Data Start **")
Dim ev As WebBaseEvent
For Each ev In events
formatter.AppendLine(String.Format("Message: {0}", _
ev.Message))
formatter.AppendLine(String.Format("Source: {0}", _
ev.EventSource.ToString()))
formatter.AppendLine(String.Format("Code: {0}", _
ev.EventCode.ToString()))
Next ev
formatter.AppendLine("**SampleWebBaseEventCollection Data End **")
formatter.IndentationLevel -= 1
End Sub
End Class
注解
ASP.NET 运行状况监视允许生产和运营人员管理已部署的 Web 应用程序。 命名空间 System.Web.Management 包含负责打包应用程序运行状况状态数据的运行状况事件类型和负责处理此数据的提供程序类型。 它还包含支持类型,这些类型有助于管理运行状况事件。
该 WebBaseEventCollection 类用于将运行状况监视事件的集合传递给提供程序,例如 SqlWebEventProvider。
构造函数
WebBaseEventCollection(ICollection) |
初始化 WebBaseEventCollection 类的新实例。 |
属性
Count |
获取 ReadOnlyCollectionBase 实例中包含的元素数。 (继承自 ReadOnlyCollectionBase) |
InnerList |
获取 ReadOnlyCollectionBase 实例中包含的元素的列表。 (继承自 ReadOnlyCollectionBase) |
Item[Int32] |
获取位于指定索引位置的 WebBaseEvent 对象。 |
方法
Contains(WebBaseEvent) |
指示集合中是否包含指定的 WebBaseEvent 对象。 |
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetEnumerator() |
返回循环访问 ReadOnlyCollectionBase 实例的枚举器。 (继承自 ReadOnlyCollectionBase) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
IndexOf(WebBaseEvent) |
获取指定 WebBaseEvent 对象的索引。 |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |
显式接口实现
ICollection.CopyTo(Array, Int32) |
从目标数组的指定索引处开始将整个 ReadOnlyCollectionBase 复制到兼容的一维 Array。 (继承自 ReadOnlyCollectionBase) |
ICollection.IsSynchronized |
获取一个值,该值指示对 ReadOnlyCollectionBase 对象的访问是否同步(线程安全)。 (继承自 ReadOnlyCollectionBase) |
ICollection.SyncRoot |
获取一个对象,该对象可用于同步对 ReadOnlyCollectionBase 对象的访问。 (继承自 ReadOnlyCollectionBase) |
扩展方法
Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定的类型。 |
OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |
AsParallel(IEnumerable) |
启用查询的并行化。 |
AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |