I add to write to a log in a download process.
In that process, the loop store three files at a time (loop time).
The write log process is
Create the text file in the Try statement
In the loop:
a. download file 1 on 3
b. WriteLine Download "
c. go back to a for file 2 on 3
d. WriteLine Download "
e. go back to a for file 3 on 3
f. WriteLine Download "
g. back to the start of the loop
h. Close the Try statement.
The question I am asking (you and me) is:
Isnt it better to:
a. create the log file
b. close the log file
In the download loop:
c. Save the image 1 on 3
d. Open the log file (and set the Try bloack)
e. Append the text log line
f. Close the text log line
g. Close the Try block
h. Close the Save file 1 on 3
and so on for the other 2 download files.
Back to the start of the Loop.
Why do I ask ?
That annoy me to think the Try block holds my (nearly) whole code. But must I think at these kind of things ?
TIA for your advice(s)
- create a log file (if not exist) else re-open last?
- write the lines
- close the file
Or you can make a buffer (string) write to it then if you have all downloads for the moment, write it to the file.
Then re-do it when needed.
it’s aound 1,000 line for each year.
[quote=309477:@Emile Schwarz]it’s aound 1,000 line for each year.
One or some files will do.
I could fit in a single file.
Best to write, and close in the same method.
The your sure it’s stored if the app or computer is closed.
Use a string array, and write out the strings to the log file once, that way you’re not holding the text file open for so long.
[code]dim arsLogs() as String
for i as integer = 0 to ar?Downloads.Ubound
// download file
WriteFile Join(arsLogs, EndOfLine)
That what was worried me, but I could not wrote it.
On the other hand, if the application / computer hang, in the other process I keep a track of what have been saved (done).Other question: what good keeping track of this can be ?
For the record:
I keep the code part that ( where it originally was and still is):
a. create the log folder
b. create an empty log file (Using BinaryStream):
Log_Name = "Log - " + ReplaceAll(Log_Date.SQLDateTime, “:”, “-”) + “.txt”
c. I created a method to append several information for each download item (file name, file size, ordered (and selected) Headers and the header block (.Source). [this in a Try block).
To make the log readable, I added an intro line, a, b and c entries and some empty lines.
d. I noticed that the file length (I get from the FolderItem used to store the downloaded item) is empty, most of the time. So I add
.Flush before closing the
BinaryStream: now I have my item size.
e. Close the TextOutputStream.
At last, the log file will take size on the hard disk, but since no one cares
Looks like I am happy with that.
Thank you all.