[RESOLVED] Creating/Maintaining log files
Results 1 to 4 of 4

Thread: [RESOLVED] Creating/Maintaining log files

  1. #1
    Deity
    Guest

    Post Creating/Maintaining log files

    I recently posted with questions regarding program execution and FTP transfers. All that is working perfectly, but now I have another dilema.

    I'm trying to create simple log files in the VB program to track activity with the FTP. The files are simple ASCII text files, using sequential file access methods to write the data. As an option on this program I would like the administrator to have the ability to set a maximum file size and whether the log file should be overwritten or deleted when the maximum is reached. All the code is working in regard to writing the file, setting the maximum and deleting if the maximum is reached, but I'm not sure how to control overwriting the log.

    The log appends itself to the bottom of the document. I would like to be able to delete the top entry(which is always the same number of lines) and then append to the bottom. This would keep the log file at the same file size each time it is written to.

    I'm just not sure how exactly to do this. Suggestions? Comments?

    Thanks in advance.

    ------------------
    When the going gets tough, the tough give up.

  2. #2
    Registered User
    Join Date
    Jan 1999
    Location
    London, Great Britain
    Posts
    300

    Post

    Visual Basic is not very good at file access - there are very limited functions which means doing complicated things (like overwriting a file) are near on impossible!

    VB only allows you to append to the end of the file or to start the file fresh - you can't insert data into a file at a specific point. What you're going to have to do is to read the file into an area (either memory or into a temp file) until you reach the point you want to insert/overwrite. Then you need to write out your new line. Finally, you need to carry on reading the file until you hit the end to get the rest of it.

    Depending on the size of the file, you may find it quicker to do it in memory than using a temporary file.

    HTH.


    ------------------
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>

  3. #3
    Deity
    Guest

    Post

    Not exactly the answer I was hoping to hear, but at least you confirmed my thoughts on the matter. For this program, it's probably not worth it to go through the hassle of writing the code for that. This is supposed to be small fast and efficient, I think I can convince the boss to accept the delete only method.

    Thanks for your help antonye.

    ------------------
    When the going gets tough, the tough give up.

  4. #4
    QSECOFR
    Guest

    Post

    If you could keep a counter in a 2nd file, and if that counter is over x, then you could do some writing where you ignore the first record when you read the existing log file to write to a temp file, then append the new entry. then replace the old logfile with the temp. But it is complicated, and has a greater potential for errors that way.

    ------------------
    "I see dumb people....they're everywhere. They walk around like everyone else. They don't even know they're dumb"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •