EventLog.Clear 方法
定义
从事件日志中移除所有项。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 log does not exist.
示例
下面的示例将清除事件日志。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.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
注解
使用最大大小设置事件日志,以确定可以包含的条目数。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.