EventLog.Clear 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从事件日志中移除所有项。
public:
 void Clear();public void Clear ();member this.Clear : unit -> unitPublic Sub Clear ()例外
没有为 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.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
End Class
注解
事件日志设置为最大大小,用于确定其可以包含的条目数。 当事件日志已满时,它会停止记录新的事件信息,或开始覆盖以前的条目。 如果事件记录停止,可以使用此方法清除现有条目的日志,并允许它再次开始记录事件。 您必须对日志所在的计算机具有管理员权限才能清除事件日志条目。
Clear 关闭事件日志,释放事件句柄,检索新的读取和写入句柄,并重新打开事件日志。 调用 方法后收到的事件不会与现有事件一起清除。