The LOG_EVENT method
Published 12 NOV 2012 at 07:30:38AM
Updated on 24 APR 2013 at 07:30:38AM
In an earlier post we took a very brief look at some of the new properties of the SYSTEM object, and this time we thought we'd take a closer look at one of it's new methods called LOG_EVENT.
Simply put the LOG_EVENT method allows you to write a message to the Windows Event Log without the need for you to prototype and use any Windows API functions yourself. It's very easy to use and takes three arguments:
1) Type Info: This is a dynamic array comprised of the following fields:
<1> Message Type (Required) : "ERROR", "WARNING" or "INFO". <2> Event ID (Optional) : Integer denoting the event. Defaults to 1. <3> Category ID (Optional) : Integer identifying the category. Defaults to 0.
2) Source Info: This is a dynamic array comprised of the following fields:
<1> Event Source (Required) : Name of the Event Source (See below). <2> Server Name (Optional) : UNC Name of the system to post the message to. Defaults to the local workstation.
3) Message Text: This is simply the text of the message to post to the Event Log.
Example: Post an error message to the Event Log from the "RevPS" Event Source:
x = exec_Method( "SYSTEM", "LOG_EVENT", "ERROR", "RevPS", "FOOBAR!!!!" )
The Event Source name
So far, so good. However if you simply execute the above code you will see the message you posted in the Application Event Log, but you'll also see that Windows has prefixed your message with some of it's own text which refers to a missing Event ID description like so:
The reason for this is that Windows expects to find a "registered Event Source" containing the description for the Event ID that you specified. A registered Event Source is actually a DLL containing a set of strings, each of which corresponds to an Event ID. Without this DLL you get the warning text you see above which doesn't look very professional and gives the impression that something is missing from your application.
For OpenInsight v10 we have provided a generic DLL called RevEventMsg.dll that you can register on your system under your desired Event Source name - if you then use that name in your call to the LOG_EVENT method you will see your message without any of the warning text prefixed to it.
Registering the DLL is quite simple: you need to create a new key with the name of your Event Source (We used the string "RevPS" for this example) under this path:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\
… and set a couple of values like so (this can be automated easily via a .reg file):
Now if you call the LOG_EVENT method your Event Log entry will look like this:
Much better.
If you are interested in reading further on the subject of the Windows Event Log you can find full documentation on Microsoft's MSDN website here,
[Edit: 24 Apr 13 - Call_Method renamed to Exec_Method]
(Disclaimer: This article is based on preliminary information and may be subject to change in the final release version of OpenInsight 10).