WebEventProvider.Flush 方法

定义

将事件从提供程序缓冲区移到事件日志中。Moves the events from the provider's buffer into the event log.

public:
 abstract void Flush();
public abstract void Flush ();
abstract member Flush : unit -> unit
Public MustOverride Sub Flush ()

示例

下面的代码示例说明如何使用 Flush 方法。The following code example shows how to use the Flush method.

// 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();

}
' 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
 

注解

调用此方法时,缓冲区中的所有事件都会立即从缓冲区移到事件日志中,无论自上次写入以来经过了多少时间或缓冲区中有多少事件。When this method is called, all the events in the buffer are immediately moved from the buffer to the event log, regardless of how much time has elapsed since last write or how many events are in the buffer. 上次写入的时间将重置为刷新操作的时间。The time of the last write is reset to the time of the flushing action.

适用于