Hello All,
Trying to implement global exception handling in a service, but I can't seem to get it to work. Is there something I'm missing?
I am trying to do the following:
in my ServiceExecute, and:
under 'Type'.
The logging procedure itself is:
What am I doing wrong? I know that, since this is a service, things might work a bit differently, so how would I do it then?
Also, how would I do it for ANY non-VCL program.
Thanks,
-Tony
Trying to implement global exception handling in a service, but I can't seem to get it to work. Is there something I'm missing?
I am trying to do the following:
Code:
ApplicationEvents := TApplicationEvents.Create(nil);
ApplicationEvents.OnException := LogException;
in my ServiceExecute, and:
Code:
TMMRS_tony = class(TService)
procedure ServiceExecute(Sender: TService);
public
procedure LogException(Sender: TObject; E: Exception);
function GetServiceController: TServiceController; override;
end;
under 'Type'.
The logging procedure itself is:
Code:
procedure TMMRS_tony.LogException( Sender: TObject; E: Exception );
var
Filename: string;
LogFile: TextFile;
begin
Filename := ChangeFileExt ('RelayServer','.log');
AssignFile (LogFile, Filename);
if FileExists (FileName) then
Append (LogFile)
else
Rewrite (LogFile);
try
Writeln (LogFile, DateTimeToStr (Now) + ':' + E.Message);
finally
CloseFile (LogFile);
end;
end; (* LogException *)
What am I doing wrong? I know that, since this is a service, things might work a bit differently, so how would I do it then?
Also, how would I do it for ANY non-VCL program.
Thanks,
-Tony