WebEventProvider 클래스

정의

버퍼링되지 않은 이벤트 공급자에 대한 기본 클래스를 제공합니다.

public ref class WebEventProvider abstract : System::Configuration::Provider::ProviderBase
public abstract class WebEventProvider : System.Configuration.Provider.ProviderBase
type WebEventProvider = class
    inherit ProviderBase
Public MustInherit Class WebEventProvider
Inherits ProviderBase
상속
WebEventProvider
파생

예제

다음 코드 예제에서 파생 하는 방법을 보여 줍니다는 WebEventProvider 적절 한 액세스 권한이 부여 되어 있는 로컬 파일에 구성 된 이벤트를 기록 하는 사용자 지정 공급자를 만드는 클래스입니다. 이 사용자 지정 공급자 예는 간단 하 고 해당 주 목적은 개발자 전체 컨트롤의 기본 메커니즘을 제공 하는 것입니다. 실제 시나리오를 사용 하 여이 공급자와 특히 버퍼링 하는 예제 공급자에서 사용할 수 있는 BufferedWebEventProvider, 예비 프로브 애플리케이션의 동작을 합니다. 이 도움이 될 수 있습니다; 사용 가능한 정보를 파악 하기 위해 디자인 단계 그런 다음 나중에 더 복잡 한 공급자에이 정보를 보낼 수 있습니다.

다음 구성 파일에 인용한는 healthMonitoring 모든 상태 모니터링 이벤트를 처리 하려면 앞에서 정의한 사용자 지정 공급자를 사용 하는 ASP.NET을 사용 하도록 설정 하는 섹션 구성 합니다.

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

    <providers>  

      <add name="SampleWebEventProvider"   
        type="SamplesAspNet.SampleEventProvider,webeventprovider, Version=1.0.1773.33989, Culture=neutral, PublicKeyToken=cf85aa6c978d9dea, processorArchitecture=MSIL" />  

    </providers>  

    <rules>  

      <rule   
        name="Custom Event Provider"  
        eventName="All Events"  
        provider="SampleWebEventProvider"  
        profile="Default" />  
    </rules>  

</healthMonitoring>  

using System;
using System.Text;
using System.IO;
using System.Web.Management;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;

namespace SamplesAspNet
{
  // Implements a custom event provider.
    public class SampleEventProvider : 
        System.Web.Management.WebEventProvider
    {

        // The local path of the file where
        // to store event information.
        private string logFilePath;
    
        // The current number of buffered messages 
        private int msgCounter;

        // The max number of messages to buffere.
        private int maxMsgNumber;

        // The message buffer.
        private System.Collections.Generic.Queue
            <WebBaseEvent> msgBuffer = 
            new Queue<WebBaseEvent>();

        // Initializes the provider.
        public SampleEventProvider(): base()
        {

            // Initialize the local path of the file 
            // that holds event information.
            logFilePath = "C:/test/log.doc";

            // Clear the message buffer.
            msgBuffer.Clear();

            // Initialize the max number of messages
            // to buffer.
            maxMsgNumber = 10;

            // More custom initialization goes here.
        }

        // Flush the input buffer if required.
        public override void Flush()
        {
            // Create a string builder to 
            // hold the event information.
            StringBuilder reData = new StringBuilder();

            // Store custom information.
            reData.Append("SampleEventProvider processing." +
                Environment.NewLine);
            reData.Append("Flush done at: {0}" +
                DateTime.Now.TimeOfDay.ToString() +
                Environment.NewLine);
            
            foreach (WebBaseEvent e in msgBuffer)
            {
                // Store event data.
                reData.Append(e.ToString());
            }

            // Store the information in the specified file.
            StoreToFile(reData, logFilePath, FileMode.Append);

            // Reset the message counter.
            msgCounter = 0;
            
            // Clear the buffer.
            msgBuffer.Clear();
        }


        // Shutdown the provider.
        public override void Shutdown()
        {
            Flush();
        }


        // Process the event that has been raised.
        public override void ProcessEvent(WebBaseEvent raisedEvent)
        { 
            if (msgCounter < maxMsgNumber)
            {
                // Buffer the event information.
                msgBuffer.Enqueue(raisedEvent);
                // Increment the message counter.
                msgCounter += 1;
            }
            else
            {
                // Flush the buffer.
                Flush();
            }
        }



        // Store event information in a local file.
        private void StoreToFile(StringBuilder text, 
            string filePath, FileMode mode)
        {
            int writeBlock;
            int startIndex;

            try
            {

                writeBlock = 256;
                startIndex = 0;

                // Open or create the local file 
                // to store the event information.
                FileStream fs = new FileStream(filePath, 
                    mode, FileAccess.Write);

                // Lock the file for writing.
                fs.Lock(startIndex, writeBlock);

                // Create a stream writer
                StreamWriter writer = new StreamWriter(fs);

                // Set the file pointer to the current 
                // position to keep adding data to it. 
                // If you want to rewrite the file use 
                // the following statement instead.
                // writer.BaseStream.Seek (0, SeekOrigin.Begin);
                writer.BaseStream.Seek(0, SeekOrigin.Current);

                //If the file already exists it must not 
                // be write protected otherwise  
                // the following write operation fails silently.
                writer.Write(text.ToString());

                // Update the underlying file
                writer.Flush();

                // Unlock the file for other processes.
                fs.Unlock(startIndex, writeBlock);

                // Close the stream writer and the underlying file     
                writer.Close();

                fs.Close();
            }
            catch (Exception e)
            {
                throw new Exception(
                    "SampleEventProvider.StoreToFile: " 
                    + e.ToString());
            }
        }
    }
}
Imports System.Text
Imports System.IO
Imports System.Web.Management
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports System.Web



' Implements a custom event provider.

Public Class SampleEventProvider
    Inherits System.Web.Management.WebEventProvider
    
    ' The local path of the file where
    ' to store event information.
    Private logFilePath As String
    
    ' The current number of buffered messages 
    Private msgCounter As Integer
    
    ' The max number of messages to buffere.
    Private maxMsgNumber As Integer
    
    ' The message buffer.
    '  private System.Collections.Generic.Queue
    Private msgBuffer _
    As System.Collections.Generic.Queue( _
    Of System.Web.Management.WebBaseEvent) = _
    New System.Collections.Generic.Queue( _
    Of System.Web.Management.WebBaseEvent)


    ' Initializes the provider.
    Public Sub New() 
        
        ' Initialize the local path of the file 
        ' that holds event information.
        logFilePath = "C:/test/log.doc"
        
        ' Clear the message buffer.
        msgBuffer.Clear()
        
        ' Initialize the max number of messages
        ' to buffer.
        maxMsgNumber = 10
    
    End Sub
     
    ' More custom initialization goes here.
    
    ' Flush the input buffer if required.
    Public Overrides Sub Flush() 
        ' Create a string builder to 
        ' hold the event information.
        Dim reData As New StringBuilder()
        
        ' Store custom information.
        reData.Append( _
        "SampleEventProvider processing." + _
        Environment.NewLine)

        reData.Append( _
        "Flush done at: {0}" + _
        DateTime.Now.TimeOfDay.ToString() + _
        Environment.NewLine)
        
        Dim e As WebBaseEvent
        For Each e In  msgBuffer
            ' Store event data.
            reData.Append(e.ToString())
        Next e
        
        ' Store the information in the specified file.
        StoreToFile(reData, logFilePath, FileMode.Append)
        
        ' Reset the message counter.
        msgCounter = 0
        
        ' Clear the buffer.
        msgBuffer.Clear()
    
    End Sub
     
    ' Shutdown the provider.
    Public Overrides Sub Shutdown() 
        Flush()
    
    End Sub
    
    ' Process the event that has been raised.
    Public Overrides Sub ProcessEvent( _
    ByVal raisedEvent As WebBaseEvent)

        If msgCounter < maxMsgNumber Then
            ' Buffer the event information.
            msgBuffer.Enqueue(raisedEvent)
            ' Increment the message counter.
            msgCounter += 1
        Else
            ' Flush the buffer.
            Flush()
        End If

    End Sub
    
    
    ' Store event information in a local file.
    Private Sub StoreToFile( _
    ByVal [text] As StringBuilder, _
    ByVal filePath As String, _
    ByVal mode As FileMode)
        Dim writeBlock As Integer
        Dim startIndex As Integer

        Try

            writeBlock = 256
            startIndex = 0

            ' Open or create the local file 
            ' to store the event information.
            Dim fs As New FileStream( _
            filePath, mode, FileAccess.Write)

            ' Lock the file for writing.
            fs.Lock(startIndex, writeBlock)

            ' Create a stream writer
            Dim writer As New StreamWriter(fs)

            ' Set the file pointer to the current 
            ' position to keep adding data to it. 
            ' If you want to rewrite the file use 
            ' the(following) statement instead.
            ' writer.BaseStream.Seek (0, SeekOrigin.Begin);
            writer.BaseStream.Seek(0, SeekOrigin.Current)

            'If the file already exists it must 
            'not be write protected, otherwise  
            'the following write operation fails silently.
            writer.Write([text].ToString())

            ' Update the underlying file
            writer.Flush()

            ' Unlock the file for other processes.
            fs.Unlock(startIndex, writeBlock)

            ' Close the stream writer and the underlying file     
            writer.Close()

            fs.Close()
        Catch e As Exception
            Throw New Exception( _
            "SampleEventProvider.StoreToFile: " + _
            e.ToString())
        End Try

    End Sub
End Class

설명

ASP.NET 상태 모니터링 프로덕션와 운영 스태프를 배포 된 웹 애플리케이션을 관리할 수 있습니다. System.Web.Management 네임 스페이스에는 애플리케이션 상태 데이터 및이 데이터 처리를 담당 하는 공급자 형식이 패키징 담당 상태 이벤트 유형을 포함 합니다. 또한 상태 이벤트를 관리 하는 동안 유용한 지 원하는 형식을 포함 합니다.

상태 이벤트 처리를 사용자 지정 하려는 경우에서 파생할 수 있습니다는 WebEventProvider 사용자 고유의 사용자 지정 공급자를 만드는 클래스입니다.

참고

대부분의 경우에 구현 된 대로 ASP.NET 상태 모니터링 유형을 사용할 수 없게 됩니다 및에서 값을 지정 하 여 상태 모니터링 시스템을 제어 하는 healthMonitoring 구성 섹션입니다. 사용자 고유의 사용자 지정 이벤트 및 공급자 상태 모니터링 형식에서 파생할 수 있습니다. 파생의 예는 WebEventProvider 클래스,이 항목에 제공 된 예제를 참조 하세요.

생성자

WebEventProvider()

WebEventProvider 클래스의 새 인스턴스를 초기화합니다.

속성

Description

관리 도구나 다른 UI(사용자 인터페이스)에 표시하기에 적합한 간단하고 이해하기 쉬운 설명을 가져옵니다.

(다음에서 상속됨 ProviderBase)
Name

구성 중 공급자를 참조하는 데 사용되는 이름을 가져옵니다.

(다음에서 상속됨 ProviderBase)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
Flush()

공급자의 버퍼에서 이벤트 로그로 이벤트를 옮깁니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Initialize(String, NameValueCollection)

구성 작성기를 초기화합니다.

(다음에서 상속됨 ProviderBase)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ProcessEvent(WebBaseEvent)

공급자에 전달된 이벤트를 처리합니다.

Shutdown()

공급자 종료와 관련된 작업을 수행합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보