I created this Method in the App of a web application:
sub WriteLog(lsText as String)
Dim f As FolderItem
Dim t as TextOutputStream
f = GetFolderItem("Log.Text")
Dim ld as New Date
If f = Nil then
t = TextOutputStream.Create(f)
end
t = TextOutputStream.Append(f)
t.WriteLine( ld.ShortDate + " " + ld.LongTime + " - " + lsText)
t.Close
end sub
It will only work once, after the app quits it will no longer write to the file. Nothing at all.
f=nil is not the same as f.exists = false, so your code is not right.
I would write this:
If f = Nil then
msgbox "Bad error, couldn't open my log file"
App.Quit
else if not f.exits then
t = TextOutputStream.Create(f)
else
t = TextOutputStream.Append(f)
end if
Also, that’s going to be horribly inefficient, to constantly be re-creating the TOS.
I would create or open the TOS once, then keep a reference to the TextOutputStream open while the app is running. Don’t re-open it with every log.
Use .Flush() to ensure that data gets written promptly.
I wasn’t really looking for efficiency, I’m try to figure out what events in a web cgi app and in what order. I have an issue where an app didn’t quit, remained in memory and finally caused an internal server error when someone tried to access it.
[quote=230136:@Bob Keeney] #if TargetXojoCloud then
f = SpecialFolder.SharedDocuments.child(“WebComm”).child(“log.txt”)[/quote]
Bob. How do you keep multiple users from grabbing the file at the same moment?
Perhaps you don’t need to: We have been chasing bad crash in XC for a while now we think we have narrowed it to the mysql plugin but the good folks at Xojo (who went above and beyond with their support on this one) had us rewrite our login code so that we wrote to an array in App. Then had a timer spool the log file one item at a time.
The feeling was that perhaps grabbing the log file by two session was causing crashes.
This method is in the application object. And I should add that I don’t use this much for production so it’s not been stressed tested by multiple users at the same time.