Reusable Logging in VBScript – LogToFile.vbs

Frequently I have had the need to log certain information or messages to a log file as script is running. Since this is such a frequent requirement, and adding logging to a script can be a messy affair since it’s often an after thought. I decided to write a sub routine that you could easily call and it would do the work for you.

When using the following script, you simply prepend the configuration section to the beginning of the script, decide how you’d like the script to behave by changing the various options, and then append the sub portion to the end of the script.

Anywhere you’d like to log a message within the script you’d simply add LogToFile “Your Message” to log the relevant information.

With this script you can log the date and time you began the script, the date and time of any particular events, and generate unique file names if you want to schedule script run times. It’s also simple to turn off logging without editing the entire logging section out.


Leave a Comment