12-06-2012, 06:21 PM
Below is the code for creating the log file,
It will update the date and time followed by the message. Later it can be used for analysis.
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Function to write a log file>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'This function is used to create logs
'The log file will be stored with filename as "Logfile.log" by default
'If the log file is present in the path specified, it will be updated else it will be created.
'StrTitle -> Used to give the Title for the log. Eg: Test
'StrMessage -> The message which needs to be sent
Usage: Writetolog("Test", "This is a test")
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hope this helps.
Let me know in case of any questions.
Thanks,
Elango
It will update the date and time followed by the message. Later it can be used for analysis.
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Function to write a log file>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'This function is used to create logs
'The log file will be stored with filename as "Logfile.log" by default
'If the log file is present in the path specified, it will be updated else it will be created.
'StrTitle -> Used to give the Title for the log. Eg: Test
'StrMessage -> The message which needs to be sent
Usage: Writetolog("Test", "This is a test")
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Code:
Function Writetolog(StrTitle, StrMessage)
Dim objFS, Logfilepath, ObjFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Logfilepath = Pathofthefolderwherelogfileshouldbestored & "Logfile.log" 'Enter the log file path here
If objFS.FileExists(Logfilepath) Then
Set objFile = objFS.OpenTextFile(Logfilepath,8,False)
Else
objFS.CreateTextFile Logfilepath,True
Set objFile = objFS.OpenTextFile(Logfilepath,8,False)
End If
objFile.Write "[" & Date &"]" & "[" & Time & "][" & StrTitle &"][" & StrMessage & "]" &vbcrlf
objFile.Close
Set objFile = Nothing
Set objFS = Nothing
End Function
Hope this helps.
Let me know in case of any questions.
Thanks,
Elango