Categories
Dynamics NAV / Navision

Dynamics NAV – writing logs

Something we need in every serious code object- writing logs to a logfile.

{
1)  open log file
}
OpenLogFile()

ltePath:=getMainPath('')+'csvlog.txt';

LogFile.TEXTMODE := TRUE;
LogFile.WRITEMODE(TRUE);
IF NOT LogFile.OPEN(ltePath) THEN
    IF NOT LogFile.CREATE(ltePath) THEN BEGIN
        EXIT; 
    END;
LogFile.SEEK(LogFile.LEN);
{
2) write text line
WriteLog(mess : Text[1000])
LogFile.WRITE(mess);
}
{
3) don't forget to close the file at the end
}
CloseLogFile()
LogFile.CLOSE();

Leave a Reply

Your email address will not be published. Required fields are marked *