When properly registered, a custom event log is listed in Application and Services Logs. A picture below displays custom event log MyEventLog opened in Windows Event Viewer.

Such log can be created through adding several Registry keys and values. Required Registry entries can be produced either manually (use Windows RegEdit or any similar utility) or programmatically (assumes admin rights).

MaxSize = maximum size, in bytes, of the log file. This value is of type REG_DWORD. The value must be set to a multiple of 64K for a System, Application, or Security log. The default value is 1MB.
Read more about Eventlog Keys on MSDN.

EventMessageFile value normally contains the path to a DLL or EXE file containing message resources designed for a particular application.
To fill the blank, the path to .NET message resource file is used -- C:\Windows\Microsoft.NET\Framework64\v2.0.50727\EventLogMessages.dll -- in real life to be substituted with application-specific file.
* * *
Note that the code below creates objects from classes implemented in Windows Registry class library. Before testing this code sample, store the library code in RegistryClassLib.PRG file.
VFP Registry Access Foundation Class contains all required functionality, and also can be used for building a similar code.
* * *
Note that VFP session or VFP application intended to access the Registry must be started with admin privileges.
See also:
Writing entries to custom Event Log
Reading entries from Event logs |
#DEFINE HKEY_LOCAL_MACHINE 0x80000002
#DEFINE REG_PATH_EVENTLOG;
"SYSTEM\CurrentControlSet\services\eventlog"
#DEFINE MESSAGE_SOURCE_DLL;
"C:\Windows\Microsoft.NET\Framework\" +;
"v2.0.50727\EventLogMessages.dll"
DO CreateEventSource;
WITH "MyEventLog", "MyEventSource"
* end of main
PROCEDURE CreateEventSource(cLogName As String,;
cSourceName As String)
*** save code sample #472 in RegistryClassLib.PRG
SET PROCEDURE TO RegistryClassLib ADDITIVE
***
LOCAL oRegistry As Registry, oEventlogKey As regkey,;
oAppLogKey As regkey, oEventSourceKey As regkey
oRegistry = CREATEOBJECT("Registry")
oEventlogKey = CREATEOBJECT("regkey",;
HKEY_LOCAL_MACHINE, REG_PATH_EVENTLOG)
IF oEventlogKey.OpenKey()
IF oEventlogKey.subkeyexists(m.cLogName, .T.)
oAppLogKey = CREATEOBJECT("regkey",;
oEventlogKey.hKey, m.cLogName)
WITH oAppLogKey
IF .OpenKey()
.SetValue("AutoBackupLogFiles", 4, 0)
.SetValue("MaxSize", 4, 0x80000)
IF .subkeyexists(m.cSourceName, .T.)
oEventSourceKey = CREATEOBJECT("regkey",;
oAppLogKey.hKey, m.cSourceName)
WITH oEventSourceKey
IF .OpenKey()
.SetValue("EventMessageFile",;
2, MESSAGE_SOURCE_DLL)
ENDIF
ENDWITH
ENDIF
ENDIF
ENDWITH
ENDIF
ENDIF
|