Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Generic Log File

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,25831
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Generic Log File
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Generic Log File - 9/11/2005 11:18:21 PM   
  mbouchard


Posts: 1804
Score: 12
Joined: 5/15/2003
From: USA
Status: online
I am posting this in response to another post.

This is a sub that I use in many of my scripts, it will create the log file if it is not already present, it will then open the file and append to it whenever the sub is called.

'Do something here
Call WriteToLog("Some Info Here")
'Do something else here

Sub WriteToLog(Message) ' For writing description of installation to Software Configuration.log
    Const FORREADING = 1
    Const FORWRITING = 2
    Const FORAPPENDING = 8
   
    Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
    Dim fLog, strLogFile, strLogFileLoc
    strLogFile = "Name of Some Log Here" ' ex. Software Configuration
    strLogFileLoc = "c:\program files\" & strLogFile & ".log"
    ' Create the log file if it does not exist
    If not Fso.FileExists(strLogFileLoc) Then
        Set fLog = Fso.CreateTextFile(strLogFileLoc, True)
        fLog.WriteLine(strLogFile & " Log")' i.e. Software Configuration Log
        fLog.Close
    End If
    ' Append to the log file
    Set fLog = Fso.OpenTextFile(strLogFileLoc, FORAPPENDING)
    If Message = "" Then
        fLog.WriteLine("")
        flog.Close
    Else
        'Writes the message to the log file, prefixed by the Date/Time
        fLog.WriteLine(Now & "  " & Message)
        fLog.Close
    End If
End Sub
        fLog.WriteLine(Now & "  " & Message)
        fLog.Close
    End If
End Sub

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Generic Log File Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts