|
Log Object |
|
See Also: |
The Log.LogEvent() method writes an entry to the Windows NT Event Log.
VBScript:
JScript:
| Log | The Log object. |
| strText | Text to be written to the log entry. |
| severity | Optional. An ApgLogSeverityEnum value. The default value is apgSeverityInfo. |
| lngCode | Optional. A long integer value to be written to the log entry. The default value is zero. |
The NT Event Log provides a standard, centralized way for applications (and the operating system) to record important software and hardware events. Windows NT supplies the Event Viewer for viewing and filtering the Event Log, and a programming interface for examining the Log. In addition, administrators can view Event Logs on remote computers, and many system management tools provide access to Event Logs.
Microsoft recommends that only important events be logged to the Windows NT Event log, because the log can become full. APGen leaves it up to each script author to determine which events are important.
Script errors can be automatically logged in the NT Event Log. If the apgEventLogFatalErrors flag is enabled in Log.Flags, all fatal errors are reported to the NT Event Log. If the apgEventLogErrors flag is enabled in Log.Flags, all errors (fatal and non-fatal) are reported to the NT Event Log.
All events that are added to the NT Event Log have Source = "APGen". APGen reports three different event categories: APGen Fatal Errors, APGen Non-Fatal Errors, and Script Events. When Log.LogEvent() is called, the log entry will always have Category = "Script Event". Categories "APGen Fatal Error" and "APGen Non-Fatal Error" are only reported by APGen. This way, an administrator can filter out script reported events from APGen reported events.
This code snippet logs a fatal error to the NT Event Log, and aborts the script.
<%# @LANGUAGE=JScript #%>
<%#
var g_bFatalError = false;
//...
if (g_bFatalError)
{
Log.LogEvent("Fatal error occurred, script '" +
Script.Path + "' is aborting.",
apgSeverityFatal);
Script.Abort();
}
// ...
#%>