BUG: Behavior of EventLog.Delete is Not Consistent with EventLog.Exists for Log Names Longer than 8 Characters (327890)
The information in this article applies to:
- Microsoft .NET Framework Class Libraries 1.0
- Microsoft .NET Framework Class Libraries 1.1
This article was previously published under Q327890 SYMPTOMS The behavior of the EventLog.Delete() method is not consistent with the behavior of the EventLog.Exists() method for log names that are longer than 8 characters.
CAUSE The EventLog.Exists() method uses only the first 8 characters of the passed string to
determine whether a log exists. The EventLog.Delete() method uses all of the passed string to identify the log to be
deleted. This causes an inconsistency between the two methods. For
example, a user may want to verify whether a log exists and then delete it, as
shown in the following code:
if (EventLog.Exists("MyProgramLog1"))
{
EventLog.Delete("MyProgramLog1");
}
The problem is that EventLog.Exists returns TRUE if any log beginning with MyProgra
(8 characters) exists. An example scenario occurs as follows:
- MyProgramLog2 (longer than 8 characters)
exists.
- MyProgramLog1 does not exist.
- When EventLog.Delete is called, it determines whether the registry contains an entry
named MyProgramLog1.
- If EventLog.Delete does not find MyProgramLog1, an exception is
thrown.
RESOLUTION To work around this problem, instead of relying on the EventLog.Exists method to determine whether a log exists, an application confirms
the existence of the following registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\<I BRACKET="YES">LogName</ where LogName is the name of the event
log that you want to verify. STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 10/20/2003 |
---|
Keywords: | kbbug kbKernBase kbnofix KB327890 kbAudDeveloper |
---|
|