
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Changing the Maximum Size of a Custom Event Log
|
457
}
else
{
key.SetValue("MaxSize", maxSize);
Registry.LocalMachine.Close( );
}
}
Discussion
The FCL classes devoted to making use of the event log contain most of the function-
ality that a developer will ever need. Yet there are some small items that are not
directly accessible using the event log API in the FCL. One of these is the manipula-
tion of the maximum size of an event log. Event logs are initialized to a maximum
size of 512K, after which the event log entries are overwritten by default.
There are cases in which an application may produce many or very few entries in an
event log. In these cases, it would be nice to manipulate the maximum size of an
event log so that memory is used most efficiently and critical entries are not lost or
overwritten because the event log fills up too fast.
It is possible to set the maximum size of an event log manually through the Event
Viewer application. Unfortunately, you might not always have access to the machine
to do this. In addition, this is a tedious and time-consuming process. You can pro-
grammatically set the maximum size by changing the value of a registry entry. If an
event log were named
MyLog, the properties of this log would reside in the following
registry location:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyLog ...