Recipe 16.4. Viewing the Size of an Event Log


Problem

You want to find the size of an event log. This can help you determine how large an event log is and if you are close to reaching the maximum size (and therefore will start dropping events).

Solution

Using a graphical user interface

  1. Open the Event Viewer (eventvwr.msc).

  2. In the left pane, right-click on the Target Event Log and select Properties.

  3. The Size field contains the size of the event log in kilobytes and bytes.

Using a command-line interface

This command displays the file size for all of the event logs that are stored in the default location on the file system:

> dir %systemroot%\system32\config\*evt

Using VBScript
' This code displays the size of the specified event log in KB ' ------ SCRIPT CONFIGURATION ------ strLog = "<LogName>"         ' e.g. Security strComputer = "<ComputerName>"  ' e.g. wks01 (use "." for local machine) ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colLogs = objWMI.ExecQuery("Select * from Win32_NTEventlogFile Where " & _                                Logfilename = '" & strLog & "'") if colLogs.Count > 1 then    WScript.Echo "Fatal error.  Number of logs found: " & colLogs.Count    WScript.Quit end if for each objLog in colLogs    WScript.Echo strLog & " size: " & objLog.FileSize / 1024 & "KB" next

Discussion

Each event log has a corresponding event log file, which contains all of the event log messages. The size of an event log is determined by viewing the size of its event log file. By default, the %systemroot%\system32\config\ directory contains these files. Each file name directly corresponds to the name of the event log that uses it with an .evt extension (e.g., Application.evt).

See Also

Recipe 16.5 for setting the maximum size of an event log



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net