Max Log Size

VC++ 6, ATL, STL, Non-MFC

My application writes logs and now I want to setup a max log size that is configurable by the user.   I'm trying to come up with the best way of doing that without having to load up the full log into memory, which could be 2MB, then starting from the end, delete data off the top.    Is there a better way or does someone have a function that already does this?
Who is Participating?
Check out the logging library, in the following link:

The method I use, is to have two log files.  When the primary log file reaches the maximum length, I delete the old version, and rename the current log file.
Then create a new log file with the standard name.

if (maxsize)
  //Close file
  //Rename file to log.old
  //Create new file with standard name
ChizlAuthor Commented:
Thought of that, but unfortunatly, thats going to make it 2 logs with the max size, I only want 1.
>> Thought of that, but unfortunatly, thats going to make it 2 logs with the max size, I only want 1.

Then make 2 logs of half the max. log size ;)

The solution using two log files is a lot easier than removing from the file, and adding to it. Is there a specific reason that you only want one file ?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

ChizlAuthor Commented:
Client specification
>>Client specification
Many times client specifications do not lead to what is best for the client, and it's up to the developer to clarify that with the client, so that they can make an inform decision on their specifications.

The two log method is the cleanest most efficient method I found to do this.
There are other methods, that would put an impact on performance, which i would not recommend.
Well, another easy "solution" is to just erase the log file once it reaches a certain size, and start over. Although you will have periods with no or little logs ... Is that a problem ?
ChizlAuthor Commented:
Erasing is a problem..   I'm going to go with the multiple logs..   2MB max, then 1MB archive, with a 1MB working log..    They wanted the 1 file and I figured there was an good way to do that, but guess not.  

Thanks for everyone's help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.