EventLog.Clear EventLog.Clear EventLog.Clear EventLog.Clear Method

定義

移除事件記錄檔的所有項目。Removes all entries from the event log.

public:
 void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()

例外狀況

事件記錄檔未成功清除。The event log was not cleared successfully.

-或--or-

無法開啟記錄檔。The log cannot be opened. 無法使用 Windows 錯誤碼。A Windows error code is not available.

沒有指定 Log 屬性的值。A value is not specified for the Log property. 確定記錄檔名稱不是空字串。Make sure the log name is not an empty string.

範例

下列範例會清除事件記錄檔。The following example clears an event log.

警告

因為應用程式、系統、安全性和其他非自訂記錄檔可能包含重要的資訊,執行此範例程式碼之前, 請務必指定自訂記錄檔。Because Application, System, Security, and other non-custom logs can contain crucial information; be sure to specify a custom log before executing this example code. 這個範例會刪除自訂myNewLog記錄檔。This example deletes the custom log myNewLog.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   
   // Create an EventLog instance and assign its log name.
   EventLog^ myLog = gcnew EventLog;
   myLog->Log = "myNewLog";
   myLog->Clear();
}

using System;
using System.Diagnostics;
using System.Threading;
              
class MySample{

    public static void Main(){
                 
        
        // Create an EventLog instance and assign its log name.
        EventLog myLog = new EventLog();
        myLog.Log = "myNewLog";

        myLog.Clear();                                                                    
    }       
}
   
Option Explicit
Option Strict

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        ' Create an EventLog instance and assign its log name.
        Dim myLog As New EventLog()
        myLog.Log = "myNewLog"
        
        myLog.Clear()
    End Sub 'Main
End Class 'MySample

備註

事件記錄檔會以最大大小來設定, 以決定可以包含多少個專案。Event logs are set with a maximum size that determines how many entries they can contain. 當事件記錄檔已滿時, 它會停止記錄新的事件資訊, 或開始覆寫先前的專案。When an event log is full, it stops recording new event information or begins to overwrite earlier entries. 如果事件記錄停止, 您可以使用這個方法來清除現有專案的記錄, 並讓它重新開始記錄事件。If event recording stops, you can use this method to clear the log of existing entries and allow it to start recording events again. 您必須具有記錄檔所在電腦的系統管理員許可權, 才能清除事件記錄檔專案。You must have administrator permissions to the computer on which the log resides to clear event log entries.

Clear關閉事件記錄檔、釋放事件控制碼、抓取新的讀取和寫入控制碼, 然後重新開啟事件記錄檔。Clear closes the event log, releases the event handles, retrieves new read and write handles, and reopens the event log. 在呼叫方法之後所收到的事件, 並不會與現有的事件一併清除。Events received after the call to the method are not cleared along with the existing events.

安全性

EventLogPermission
用於管理電腦上的事件記錄檔資訊。for administering event log information on the computer. 相關聯的列舉:AdministerAssociated enumeration: Administer

適用於

另請參閱