How to write loop counter in logfile.

Hi,
Can anybody give me a hint on how to add a counter inside the logfile?
For example, if at first, the log file was created, it will write the current counter number, let say Log1. Everytime the application is open/launch the loop start and writes Log1, Log2, Log3, Log4 and so on for the same log filename if exist. If the file does not exist or let say a new log file was created the counter will reset to 1 and write this counter number to log file as well as the next number in the loop.

I used the below code snippet to open/create a log file.

m_oLogFileStreamopen(pcLog, ios::out|ios::app|ios::in, filebuf::sh_read|filebuf::sh_write);

hope you can help me on this

thanks & regards
gilmar
You need to check what was the last numbered file, then use the next one up.
Thanks for the quick reply.
Yes, you are right on that one.
But how can I put the last number if the application was closed? And if the user open the application after 1hour, how can I retrieved the last number and increment it and put it in the logfile?
Another thing, how can I determine if the logfile is new or not?

gilmar
Use FindFirstFile/FindNextFile/FindClose to look thru the directory.

Ord you can use stat() to check if a file exists.
Last edited on
Thanks again and sorry for the confusion.
The Log1, Log2, Log3, etc. above is not a filename, it is inside the logfile.
If I have a logfile named Oct92009MyAppLog.log, inside this log are the number of the counter Log1, Log2, Log3, etc.
Ah, sorry. I didn't read it properly.

Can you give a couple of example lines in the log file?
Topic archived. No new replies allowed.