Click to Rate and Give Feedback
MSDN
MSDN Library
Diagnostics
Windows Events
Event Logging
 ClearEventLog Function
ClearEventLog Function

Clears the specified event log, and optionally saves the current copy of the log to a backup file.

Syntax

BOOL ClearEventLog(
  __in  HANDLE hEventLog,
  __in  LPCTSTR lpBackupFileName
);

Parameters

hEventLog [in]

A handle to the event log to be cleared. This handle is returned by the OpenEventLog function.

lpBackupFileName [in]

The name of the backup file. If this file already exists, the function fails.

If the lpBackupFileName parameter is NULL, the current event log is not backed up.

Return Value

If the function succeeds, the return value is nonzero. The specified event log has been backed up (if lpBackupFileName is not NULL) and then cleared.

If the function fails, the return value is zero. To get extended error information, call GetLastError. The ClearEventLog function fails if the event log is empty or a file already exists with the same name as lpBackupFileName.

Remarks

After this function returns, any handles that reference the cleared event log cannot be used to read the log.

Examples

The following example demonstrates the use of the ClearEventLog function.

#include <windows.h>
#include <stdio.h>

BOOL MyClearLog(
  LPTSTR pszSrcName ) // event source name
{
   HANDLE hEventLog;
   BOOL bSuccess;

   hEventLog = OpenEventLog(NULL, pszSrcName);
   if (NULL == hEventLog)
   {
      printf("Open event log failed.\n");
      return FALSE;
   }

   bSuccess = ClearEventLog(hEventLog, NULL);

   CloseEventLog(hEventLog); 
   return bSuccess;
}

Requirements

ClientRequires Windows Vista, Windows XP, or Windows 2000 Professional.
ServerRequires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
HeaderDeclared in Winbase.h; include Windows.h.
LibraryUse Advapi32.lib.
DLLRequires Advapi32.dll.
Unicode/ANSIImplemented as ClearEventLogW (Unicode) and ClearEventLogA (ANSI).

See Also

Event Logging Functions
OpenEventLog


Send comments about this topic to Microsoft

Build date: 9/19/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker