A nice little extension of the File API Object to use it as an Application Engine log file. It can be disabled for performance (writing log files is incredibly slow). Automatically handles running on the client.

Plug and play.

class File extends File
   property boolean isDisabled;
   property integer debugLevel;
   method File(&name_ As string);
   method writeLine(&line_ As string);
   method debug(&line_ As string, &level_ As integer);
private
   instance boolean &_haveWrittenDisabledMessage;
   method writeDisabledMessage();
   method isRunningOnServer() Returns boolean;
end-class;

method File
   /+ &name_ as String +/
   If %This.isRunningOnServer() Then
      %Super = GetFile(&name_, "W");
   Else
      %Super = GetFile("C:\temp\\" | &name_, "W", %FilePath_Absolute);
   End-If;
end-method;

method writeLine
   /+ &line_ as String +/
   /+ Extends/implements File.WriteLine +/
   If %This.isDisabled Then
      %This.writeDisabledMessage();
      Return;
   End-If;
   %Super.WriteLine(&line_);
end-method;

method debug
   /+ &line_ as String, +/
   /+ &level_ as Integer +/
   If &level_ >= %This.debugLevel Then
      Return;
   End-If;
   %This.writeLine(&line_);
end-method;


/* private */

method writeDisabledMessage
   If &_haveWrittenDisabledMessage Then
      Return;
   End-If;
   %Super.WriteLine("Logging has been disabled.");
   &_haveWrittenDisabledMessage = True;
end-method;

method isRunningOnServer
   /+ Returns Boolean +/
   Local string &runLocation;
   SQLExec("select runlocation from psprcsrqst where prcsinstance = :1", GetRecord().PROCESS_INSTANCE.Value, &runLocation);
   Return (&runLocation = "2");
end-method;

Note that GetRecord().PROCESS_INSTANCE.Value uses the default state record.

Example

import YOUR_PACKAGE:Log:File;

Component YOUR_PACKAGE:Log:File &Log;

&Log = create YOUR_PACKAGE:Log:File("LogFile.txt");
&Log.writeLine("Started at: " | String(%Datetime));