共用方式為


WebBaseEventCollection 類別

定義

包含 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

範例

下列程式碼範例示範如何使用 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

適用於

另請參閱