Logging JScript Errors to windows event log

Writing Jscript for Dynamics CRM is a tough task, there were no errors is the data is in proper format, but somtimes i wish to log all those information & exception in some place to review/analyse. But since Jscript is not meant for this. Still there is something that you can do with Windows Event Logger. Here is a small script that uses activeXObject to write the log to eventviewer. Later you can view the log by running "eventvwer" in the cmd prompt.

Here is the script



// Creates a log object
Log.prototype = {
// adds functions to it
Err:function(Error){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(1,Error);
},
Success:function(Message){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(0,Message);
},
Warn:function(Warning){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(2,Message);
},
Info:function(Information){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(4,Information);
},
AuditSuccess:function(Message){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(8,Message);
},
AuditFailure:function(Message){
var WshShell = new ActiveXObject("WScript.shell");
WshShell.LogEvent(16,Message);
}
}

// Calling the log to write error
Log.Err("error in script");