This article contains a sample BASIC+ routine for use in OI (OpenInsight) that a developer can use to log information to the Windows Event Log on the system running OpenInsight. Writing to the event log is useful for web applications that need to log server exceptions that a system administrator can review later but it's also useful for desktop applications that need to do the same thing without bothering the user.
Writing to the event log might not be efficient or convenient when dealing with hundreds of log entries over long running processes but it is useful for important log entries that you want noticed by IT staff. When users report system problems the administrator is likely to review the event log for clues. The administrator may not be familiar with the location of custom log files or know how to access log entries saved inside the database so writing messages to the event log will make them more likely to be found.
The function below can be copied into your OpenInsight system as a store procedure and then called to write an event log message with an ERROR, WARNING, or INFO log type.
Function CS_WriteEventLog(Msg, Type) $Insert Logical common /cs_welCom/ cs_welInit@, cs_welObjHand@, cs_welUnused3@, cs_welUnused4@, cs_welUnused5@ *Either init the WSCript object or use the existing object *if previously initialized. isInit = If Assigned(cs_welInit@) Then cs_welInit@ Else False$ If isInit EQ True$ Then WScript = cs_welObjHand@ End Else WScript = oleCreateInstance("WScript.Shell") cs_welObjHand@ = WScript cs_welInit@ = True$ End *Default to INFORMATION event log types. Type = If Assigned(Type) Then Type Else "INFO" *Reference http://technet.microsoft.com/en-us/library/ee176682.aspx Begin Case Case Type _EQC "ERROR" TypeVal = 1 Case Type _EQC "WARNING" TypeVal = 2 Case Type _EQC "INFO" TypeVal = 4 Case OTHERWISE$ TypeVal = 4 ;*Default to informational End Case *Write a simple status message to Application event log. ret = OleCallMethod(WScript, "LogEvent", TypeVal, Msg) Return
For example, executing this function will write 'Hello World' to the application event log with an information log type:
CS_WriteEventLog("Hello World!", "INFO")