How to: Export, Archive, and Clear Event Logs

.NET Framework 3.5

You can manage event logs by exporting the events from the log, exporting the events and event message from the log (archiving the log), and clearing events from the event log. You can save all the events or specific events from an event log into an event log archive file (.evtx). This enables you and others to query and access the saved events directly from the saved file. You can archive event log files to keep a history of the health of a system or track the events in the security log to record the users who logged into and out of the computer.

Example

Description

The following code example uses the ExportLogAndMessages method to save the events and event message to an event log archive file. To save the events without the event messages, use the ExportLog method.

Code

No code example is currently available or this language may not be supported.

Compiling the Code

This code example requires references to the System.dll and System.Core.dll files.

Example

Description

The following code example uses the ClearLog method to clear the System event log and archives the cleared events in the specified log file.

Code

No code example is currently available or this language may not be supported.

Compiling the Code

This code example requires references to the System.dll and System.Core.dll files.

See Also

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.

Community Additions

Show: