Windows Scripting
  Home arrow Windows Scripting arrow Logging Events in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Logging Events in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-02-26

    Table of Contents:
  • Logging Events in WSH
  • Providing the Right Information
  • Constructing the Subroutines
  • Incorporating Logging into Your Script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Logging Events in WSH


    (Page 1 of 4 )

    As you advance in your abilities to work with WSH you will find yourself writing more detailed and intricate code. Many of these scripts will be system administration scripts designed to run in the background. Thus, it can be very useful for your script to generate an event log.

    Logging can be a highly detailed process.  You may want to log the events that occur as your script runs; you may also want to log any errors that are encountered.  These topics stretch far beyond the scope of a single article or series so I’ll only be giving you some basic techniques.  It will be up to you to develop them for use in your own situation and for your own scripting style.

    The most common method of logging is to a plain text file so we will be concentrating on that.  The techniques would be similar if you wanted to log to a different type of file or even to a database.  For lack of space, I’m not going into detail on how to manage the log file.  Please take the time to read my “Reading Text Files in WSH” and “Writing Text Files in WSH” articles for more information.

    The code samples in this article use predefined subroutines that I have created and made available for download.  You can use or modify these scripts any way you like.  Once you modify them to your liking, I suggest packaging them as a class so that you can reuse them in all of your scripts.

    Basically, we need to accomplish a few basic steps in our script:

    1. Identify an action taking place.
    2. Determine if that action results in an error.  If so,
    3. Make an entry for that error in our log file.

    Each event will appear on its own line in our log file.  A simple logging script might look like this:

    Const logfile = "C:log.txt"

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set objLog = objFso.CreateTextFile(logfile, True)

     

    objLog.WriteLine "Logging Started "

    objLog.WriteLine "Logging Ended "

    In this example, all we’ve done is created a text file and written a few lines to it.  This isn’t doing much good at this point.  Trust me, it will all come together.  The log.txt will look something like this.

    Logging Started

    Logging Ended

    Okay, so this log file is a bit vague.  We need to add some more information to this log if it’s going to be at all useful.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Add a whole new dimension of power and a level of professionalism to your scripts by...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek