Hello Everyone,
I wanted to accomplish logging to a file accross the network only if my ping replies would match be less than 200 MS. With that said I tried creating something that I wanted to share with the community before I use it to make sure that it's correct. This is for testing purposes so I know I need to correct the paths if I want to log to a network share etc...
If you notice, inside my While 1 ... Wend I am invoking _LogTofile() 3 times. What I want to accomplish is to only perform _FileWrite() once but capture every message. Is my code doing this - It tests fine to me just that I am having second doubts.
#include <Date.au3> Global $FlushLogs While 1 Sleep(5000) If _OnDBU() Then ConsoleWrite("ON DIALUP " & @CRLF) If Not _OnDBU() Then ConsoleWrite("NOT ON DIALUP " & @CRLF) _LogToFile(@ScriptDir & "\test.log", _Now() & " Test1") Sleep(2000) _LogToFile(@ScriptDir & "\test.log", _Now() & " Test2") Sleep(2000) _LogToFile(@ScriptDir & "\test2.log", _Now() & " Test3") $FlushLogs = True WEnd Func _LogToFile($LogFile, $message) $message = $message & @CRLF If Not _OnDBU() And $FlushLogs Then FileWrite($LogFile, @ComputerName & " " & @IPAddress1 & " " & FileGetVersion(@ScriptFullPath) & " " & $message) EndFunc Func _OnDBU() Local $Bool Local $PingServer = Ping("10.10.10.1",250) If $PingServer > 200 Then; also possible: If @error = 0 Then ... Return $Bool = False ConsoleWrite("Online, roundtrip was:" & $PingServer & " ERROR " & @error & @CRLF) Else Return $Bool = True EndIf EndFunc
This is part of my output...
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:56:45 PM Test1
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:56:47 PM Test2
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:56:54 PM Test1
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:56:56 PM Test2
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:57:03 PM Test1
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:57:05 PM Test2
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:57:12 PM Test1
S00503R001 10.10.10.12 0.0.0.0 6/14/2013 10:57:14 PM Test2