title: Write to a single log file in vbscript
body: <p>I have written a small sub to create log file</p>
  
  <pre><code>sub WriteLogFileLine(sLogFileNameFull, sLogFileLine) 
      logfolder = "C:\Users\TEMPPAHIR\LearnVB\Logfolder\"
      ScriptName1 = Replace(Wscript.ScriptName, ".vbs", "")
      sLogFileName = ScriptName1 &amp; "_" &amp; date &amp; "_" &amp; hour(now) &amp; "-" &amp; minute(now) &amp; "-" &amp; second(now) &amp; "_log.txt"
      sLogFileNameFull = logfolder &amp; sLogFileName
      dateStamp = Now()
      Set MyLog = objFSO.OpenTextFile(sLogFileNameFull, 8, True)
      MyLog.WriteLine(cstr(dateStamp) + vbTab + "-" + vbTab + sLogFileLine) 
      MyLog.Close
      Set MyLog = Nothing 
  end sub
  </code></pre>
  
  <p>I am calling this sub multiple times in my main vb script function to write messages to the log file this way,</p>
  
  <pre><code>'******************************************************************************
  '* Main Script Body
  '******************************************************************************
  Function DoAllWork
      On Error Resume Next
      Dim sFile, FromDate, ToDate, FromLocation, MyFile, objFolder, Filename, objArgs, FilenameReq, line, inFile, outFile, outputLines
      Dim FromdateFile, FromdateFileReq, lineDt, CFileDt, CopyFiles, line1, CFile, resultX, stringY, resultY, resultfinal, outputLine
      Dim FromFolderList, ToLocationArg, outputLines1, Arch, ToLocationArg1, writeOutput
      Const ForReading = 1, ForWriting = 2, ForAppending = 8 
      Set objFSO = CreateObject("Scripting.FileSystemObject") 
      Set objArgs = WScript.Arguments 
      Set MyLog = objFSO.OpenTextFile(sLogFileNameFull, 8, True)
  
      If WScript.Arguments.Count = 4 Then 
          Call WriteLogFileLine(sLogFileNameFull, "Total number of arguments passed are " &amp; WScript.Arguments.Count &amp; " and they are as follows : ")
          'Parameter1, begin with index0
          FromDate = WScript.Arguments(0)
          'Parameter2
          ToDate = WScript.Arguments(1)
          'Parameter3
          FromLocationArg = WScript.Arguments(2)
          'Parameter4
          ToLocation = WScript.Arguments(3)
      Else 
          Call WriteLogFileLine(sLogFileNameFull, "Error, Must pass 4 arguments to the script !" &amp; vbcrlf)
          Wscript.quit 
      End if 
      Call WriteLogFileLine(sLogFileNameFull, "First Argument, the date folder FROM where files needs to be copied is : " &amp; FromDate &amp; vbcrlf)
      Call WriteLogFileLine(sLogFileNameFull, "Second Argument, the date folder TILL where files needs to be copied is : " &amp; ToDate &amp; vbcrlf)
  MyLog.Close
      Set MyLog = Nothing 
  
      DoAllWork = Err.Number
      Call WriteLogFileLine(sLogFileNameFull, "End of the script !" &amp; vbcrlf)
  End Function
  
  '******************************************************************************
  '* End of the script.
  '******************************************************************************
  </code></pre>
  
  <p>But while executing the script sometimes there are multiple log files getting generated, I guess everytime the timestamp is changing it is creating a new log file and writting log in that file.</p>
  
  <p>QUE : I want all the log to be written to one single log file whose timestamp is picked up at the beginning of my script. Please help !!</p>