Compartilhar via


MOMScriptAPI.LogScriptEvent Method

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

Writes a message to the Operations Manager event log.

MOMScriptAPI.LogScriptEvent(bstrScriptName, wEventID, wSeverity, bstrDescription)

Parameters

Parameter Type Description

bstrScriptName

String

The name of the current script.

wEventID

Number

The event ID of the log entry. Any integer value from 0 to 20000.

wSeverity

Number

The severity type of the log entry. For details, see the Remarks section later in this topic.

bstrDescription

String

The description of the event.

Return Value

None.

Remarks

The messages are written to the Operations Manager event log. Use the Event Viewer to view the logged events.

The bstrScriptName can be any string value, but it is recommended that you keep the value the same as the script file name.

The following table displays the valid values for the wSeverity parameter:

Value Definition

0

Information event

1

Error event

2

Warning event

Requirements

Platforms: Requires Windows Server 2003, Windows Vista, or Windows Server 2008

Version: Requires Operations Manager 2007

Example

In the example, a VBScript checks to ensure that at least three arguments are entered. The command-line entry of LogScriptEvent.vbs {F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4} {A3485C5E-CEB2-4faa-B6BF-329BF39FA1E4} <ServerName> is valid and does not result in a message being written. The command-line entry of LogScriptEvent.vbs {F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4} {A3485C5E-CEB2-4faa-B6BF-329BF39FA1E4} is not valid, because there are fewer than three arguments and it results in a message with an Error Type and an EventID of 101 being written to the Operations Manager event log.

Option Explicit
Dim oAPI, oArgs
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments

' Check to see if the required script arguments are there.
' In this example, at least three arguments are required.
' If the arguments do not exist, log a script event.
If oArgs.Count <3 Then
    ' If the script is called without the required arguments,
    ' create an information event and then quit.
    Call oAPI.LogScriptEvent("LogScriptEvent.vbs", 101, 0, "LogScriptEvent script was called with fewer than three arguments and was not executed.")
    WScript.Quit -1
End If

' When it passes the required arguments check satisfactorily, the
' remaining script, located here, is run.

See Also

Reference

MOMScriptAPI Object