I'm trying to run a mail server and I want to keep track of the events like login, connect etc.. and I want to save this data in a log .txt file. But since it has to be done asynchronously I don't know how to lock the file for the current data append and then release it for next use. So basically I'm asking for help for a procedure called asyncAppendToFile(fileName : String; textToAppend : String)
procedure SMTPServerUserLogin(ASender: TIdSMTPServerContext;
const AUsername, APassword: String; var VAuthenticated: Boolean);
begin
asyncAppendToFile(myFile, 'User ' + AUserName + ' attempts a login');
end;
From one application, you can make a queue and put the lines there. Then a Thread check for this queue and write to the log file the lines in arriving order.
In Form Create:
In Form Destroy:
Usage: