Scripting.FileSystemObject question 
Author Message
 Scripting.FileSystemObject question

I need to write to a append to a log file, but there are several hundred
users writing to the same file. Will there be issues with logs not getting
written the way I did this.

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Function WriteToLogFile(strLogMessage)  'example use of Err object
  ForAppending = 8        'ASP doesn't recognize this is some releases
  WriteToLogFile = False  'default return value of function
  On Error Resume Next
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objLogFile = objFSO.OpenTextFile("C:\Logfiles\MyLog.txt",
ForAppending)
  Select Case Err.Number
    Case 0            'OK, do nothing
    Case 5, 50, 53    'standard file or path not found errors
      'create the custom error values and raise it back to the system
      intErrNumber = vbObjectError + 1073  'create a custom error number
      strErrDescription = "Log file has been deleted or moved."
      strErrSource = "WriteToLogFile function"
      Err.Raise intErrNumber,  strErrSource, strErrDescription
      Exit Function
    Case Else      'some other error
      'raise the standard error back to the system
      Err.Raise Err.Number, Err.Source, Err.Description
      Exit Function
  End Select
  objLogFile.WriteLine(strLogMessage)
  objLogFile.Close
  WriteToLogFile = True
End Function
</SCRIPT>



Wed, 19 Nov 2003 07:50:45 GMT  
 Scripting.FileSystemObject question
'or you can try this out?
'it will not report an error..
'because if no logfile.. it will create one
'=========================================================
dim sLogfile : sLogfile = "H:\temp\MyLog.txt"
Sub Logthis(o)
        dim fso, txt
        set fso = createobject("scripting.filesystemobject")
        if not fso.fileexists(sLogfile) then
                set txt = fso.createtextfile(sLogfile,true)
          else
                set txt = fso.opentextfile(sLogfile,8)
        end if
        txt.writeline(o)
        txt.close
        set txt = nothing
        set fso = nothing
end sub
Logthis("Perfect")
'=========================================================
'Lu?ky

Quote:
> I need to write to a append to a log file, but there are several hundred
> users writing to the same file. Will there be issues with logs not getting
> written the way I did this.

> <SCRIPT LANGUAGE=VBScript RUNAT=Server>
> Function WriteToLogFile(strLogMessage)  'example use of Err object
>   ForAppending = 8        'ASP doesn't recognize this is some releases
>   WriteToLogFile = False  'default return value of function
>   On Error Resume Next
>   Set objFSO = CreateObject("Scripting.FileSystemObject")
>   Set objLogFile = objFSO.OpenTextFile("C:\Logfiles\MyLog.txt",
> ForAppending)
>   Select Case Err.Number
>     Case 0            'OK, do nothing
>     Case 5, 50, 53    'standard file or path not found errors
>       'create the custom error values and raise it back to the system
>       intErrNumber = vbObjectError + 1073  'create a custom error number
>       strErrDescription = "Log file has been deleted or moved."
>       strErrSource = "WriteToLogFile function"
>       Err.Raise intErrNumber,  strErrSource, strErrDescription
>       Exit Function
>     Case Else      'some other error
>       'raise the standard error back to the system
>       Err.Raise Err.Number, Err.Source, Err.Description
>       Exit Function
>   End Select
>   objLogFile.WriteLine(strLogMessage)
>   objLogFile.Close
>   WriteToLogFile = True
> End Function
> </SCRIPT>



Wed, 19 Nov 2003 10:24:44 GMT  
 Scripting.FileSystemObject question
If you mean there will be several hundered users accessing the same file at
the same time, there there will be problems, afaik in vbscript you can only
open/append to one instance of the file, you cannot have multiple users
writing to the same file at the same time.

I had a similar problem writing a new site submission script for a search
engine, it stores submissions in text files which are later read by their
content management software, I ended up creating a quing system, which, if
vbscript cannot open the file, the user is places in a loop that waits for a
random number of seconds (random allows this to work for many users,
otherwist it'd only work for 2), we're only talking 1-4 seconds here, but it
takes all of 0.25-0.50 secs. to actually complete the write anyway!

After stress testing, my app could handle about 300 concurrent users, with
all writes successfull.  (managed to get it writing 100,000 lines in 5 secs)

If you need some code i'll gladly help


Quote:
> I need to write to a append to a log file, but there are several hundred
> users writing to the same file. Will there be issues with logs not getting
> written the way I did this.

> <SCRIPT LANGUAGE=VBScript RUNAT=Server>
> Function WriteToLogFile(strLogMessage)  'example use of Err object
>   ForAppending = 8        'ASP doesn't recognize this is some releases
>   WriteToLogFile = False  'default return value of function
>   On Error Resume Next
>   Set objFSO = CreateObject("Scripting.FileSystemObject")
>   Set objLogFile = objFSO.OpenTextFile("C:\Logfiles\MyLog.txt",
> ForAppending)
>   Select Case Err.Number
>     Case 0            'OK, do nothing
>     Case 5, 50, 53    'standard file or path not found errors
>       'create the custom error values and raise it back to the system
>       intErrNumber = vbObjectError + 1073  'create a custom error number
>       strErrDescription = "Log file has been deleted or moved."
>       strErrSource = "WriteToLogFile function"
>       Err.Raise intErrNumber,  strErrSource, strErrDescription
>       Exit Function
>     Case Else      'some other error
>       'raise the standard error back to the system
>       Err.Raise Err.Number, Err.Source, Err.Description
>       Exit Function
>   End Select
>   objLogFile.WriteLine(strLogMessage)
>   objLogFile.Close
>   WriteToLogFile = True
> End Function
> </SCRIPT>



Wed, 19 Nov 2003 13:32:24 GMT  
 Scripting.FileSystemObject question

Hey Rob,

would you send me an E-Mail with the source-code please?



Wed, 19 Nov 2003 19:14:35 GMT  
 Scripting.FileSystemObject question
On Sat, 2 Jun 2001 06:32:24 +0100, "Rob Black"

Quote:

>If you mean there will be several hundered users accessing the same file at
>the same time, there there will be problems, afaik in vbscript you can only
>open/append to one instance of the file, you cannot have multiple users
>writing to the same file at the same time.

>I had a similar problem writing a new site submission script for a search
>engine, it stores submissions in text files which are later read by their
>content management software, I ended up creating a quing system, which, if
>vbscript cannot open the file, the user is places in a loop that waits for a
>random number of seconds (random allows this to work for many users,
>otherwist it'd only work for 2), we're only talking 1-4 seconds here, but it
>takes all of 0.25-0.50 secs. to actually complete the write anyway!

Could you achieve the same thing with Application.Lock/Unlock?

Steve



Thu, 20 Nov 2003 08:22:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Scripting.FileSystemObject simple secutiry question.

2. Error 429 with FileSystemObject / Scripting dll

3. Scripting.FileSystemObject

4. Convert Shortpath to Path (Scripting.Filesystemobject)

5. Need Equivalent of Microsoft Scripting Runtime.FileSystemObject

6. Scripting.FileSystemObject.TYPE in System.IO

7. Scripting.FileSystemObject

8. Trouble Using "Scripting.FileSystemObject"

9. SortOrder when using Scripting.FileSystemObject

10. Set fs = CreateObject("Scripting.FileSystemObject")-error

11. Scripting.FileSystemObject

12. scripting.filesystemobject

 

 
Powered by phpBB® Forum Software