Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i continuously write to a log file?

Status
Not open for further replies.

adi316

Programmer
Sep 10, 2002
35
CA
I want to continuously write lines to a log file. I want to keep adding text to the file and not replacing the stuff i wrote before basically. how can i do it plz help, TIA.
 

Are you using the...

Open File_Name For OutPut As #File_Number

If so change the OutPut to Append

Open File_Name For Append As #File_Number

Good Luck

 
Works, ... but ...

You need to consider how much / how often this occurs. If you are writting a simple / occassional 'note of interest' or the odd err message, it is O.K.

If it is more along the lines of a 'trace log' enumerating each procedure visited, this will generate SOME (several) issues:

[tab]disc activity will dominate the process

[tab]the disc will fill fairly quickly, so you will want to "clear" the contents on occassion (probably each 'start' of the process you are tracing)

[tab]addtional concerns will arise regarding the reading / interpertation of the information recorded, as it can be (?will?) become overwhelming.


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
ok that works, but i have to open and append the file a LOT of times, i mean this file could log activity over 24 hours maybe more, and i need to constantly write the information to the file, so it could reach a few mb in size. can't this cause it to get corupted? is there no way to keep an open stream and just write to it?
 
Find some point in the app which 'denotes' the start of the process (could be the StartUp object) open the file. Figure out ALL of the 'ways out' and -in each one-, call the routine to close the file (or just close it).

A reasonable compromise MIGHT be to accumulate the info in a dynamic string array and occssionally open the text file (for APPEND) and write the array contents to the text file, ReDim the text array and start over with the write to the array. This, of course will not work for situations where you are attempting to 'catch' the final agonies of an app which is crashing, but for simple logging it can work reasonably well.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top