Question
“How can write custom information to the server log?”
Solution
Use the Server.LogWriter object to write to the server log. The LogWriter has a WriteEvent method; see the example code for details on using this method.
Download: CustomSeverLogging.zip
Sample Delphi code:
uses
rsServer,
rsServerLog;
{TfrmServerMain.FormCreate
- example of writing to server log from the main unit}
procedure TfrmServerMain.FormCreate(Sender: TObject);
begin
// TrsServerLogItemType = (seInformation, seWarning, seError, seServiceRequest, seServiceResponse);
//
// TrsServer.LogWriter.WriteEvent(aItemType: TrsServerLogItemType; aDescription: String; aSessionID: String);
//
rsServer1.LogWriter.WriteEvent(seInformation, '** myLogInfo *** FormCreate event - starting server', '');
rsServer1.Active := True;
end;
{TdmReportTemplateVolume.DataModuleCreate
- example of writing to server log from unit containing a report volume}
procedure TdmReportTemplateVolume.DataModuleCreate(Sender: TObject);
begin
// use gServer here to get access to the active TrsServer. There can
// be only one active server in an application
gServer.LogWriter.WriteEvent(seInformation, '** myLogInfo *** DataModuleCreat event', '');
rsReportTemplateVolume1.FileDirectory := TppFileUtils.GetApplicationFilePath + 'Report Files';
end;