File.Open Truncates File

bhalpinbhalpin Member Posts: 309
Hi.

To facilitate debugging, I have a codeunit with functions to open/create a 'log' file, write to the file, and close the file. I have two problems:

1 - After the file is opened/created, each call to the write function seems to truncate the file to zero length, then the text is written. The result is I never have anything in the file except the last line I wrote.

Here is the code that opens/creates the file:
LogFile.TEXTMODE(TRUE);
LogFile.WRITEMODE(TRUE);
IF NOT LogFile.OPEN(LogFileName) THEN
  LogFile.CREATE(LogFileName);

NAV documentation (typically) say's nothing about whether the file pointer is set to the start or end, whether the file is truncated, etc. And there are no options to the OPEN statement to control the behaviour (like in C.)

After fighting with it I have a solution, but it sucks:
LogFile.WRITE(ParameterValue);
LogFile.CLOSE;
LogFile.OPEN(LogFileName);
LogFile.SEEK(LogFile.LEN);

With this in place, I get all the output as expected.

But, surely I've missed something ...

2 - The code above also solves this problem, but ...

Without using any close/open tricks like above, logging of code progress to a text file seems to be useless if the code fails with a C/Side error. In this case, database changes are rolled back - (which I somethimes wish it wouldn't) AND any text file being written to is rolled back (ie deleted) as well. So I have no debug trail to see where the code failed.

Again, have I messed something?

Thanks' in advance.

Bob

Comments

Sign In or Register to comment.