Monolith Posted January 6, 2010 Share Posted January 6, 2010 (edited) Hello Was wondering if there is a "best practice" for writing to a log file (stored in a central location)when at any given time 2-20 users could be access the log file to write a entry. I have noticed if i include _FileWriteLog() or FileWriteLine() into a script and launch that script from 2 different locations one of the scripts just locks up in the function and i have to terminate the script, when they are accessing the log file @ the same time. I have tried to include the snippet below, but makes no difference one of the instances of the script will still lock up on writing to the log file. Also as mentioned i have tried FileWriteLine with @error =0 but still yields the same issue. #include <file.au3> Global $sLogPath = @ScriptDir & '\testlog.log' $run123 = Run(@ComSpec & ' / k ' & 'cmd.exe', @Systemdir, @SW_Show) $logwrite1 = _FileWriteLog($sLogPath, "Date & Time " & " " & @MDAY & "/" & @MON & " " & @HOUR & " " & @MIN) If @error = 2 Then Do Sleep(90) $bkuplogchk = $logwrite1 Until @error = 0 EndIf Do i need to use some form of FileOpen() with [optional] before attemtping to write to log file? If $file = -1 Then Sleep(90) $bkuplogchk = $logwrite1 else $logwrite1 = _FileWriteLog($sLogPath, "Date & Time " & " " & @MDAY & "/" & @MON & " " & @HOUR & " " & @MIN) EndIf Thanks is advance. Edited January 6, 2010 by Monolith Link to comment Share on other sites More sharing options...
99ojo Posted January 6, 2010 Share Posted January 6, 2010 (edited) Hi, You may change your _FileWritelog, because this function put a timestamp into logfile as well: Writes current date,time and the specified text to a log file. So you may not need the time macros. Try this: #include <file.au3> Global $sLogPath = @ScriptDir & '\testlog.log' $run123 = Run(@ComSpec & ' / k ' & 'cmd.exe', @Systemdir, @SW_Show) ;loop until text could be written to logfile. ;You might add an counter as well for exit loop after a while ;$count = 0 While 1 ;And $count < xxx If _FileWriteLog($sLogPath, "Date & Time " & " " & @MDAY & "/" & @MON & " " & @HOUR & " " & @MIN) Then ExitLoop Sleep (20) ;$count += 1 WEnd ;-)) Stefan Edited January 6, 2010 by 99ojo Link to comment Share on other sites More sharing options...
Monolith Posted January 6, 2010 Author Share Posted January 6, 2010 While 1 ;And $count < xxx If _FileWriteLog($sLogPath, "Date & Time " & " " & @MDAY & "/" & @MON & " " & @HOUR & " " & @MIN) Then ExitLoop Sleep (20) ;$count += 1 WEnd Thanks this was a simpler approach i was trialing with if $sLogPath = -1 etc etc which added more lines to the script, it worked.. but i prefer your method. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now