[fpc-pascal] TEventLog.FileName location: Change default file location for filename without change unit code.

Michael Van Canneyt michael at freepascal.org
Tue Sep 21 15:39:02 CEST 2010

On Tue, 21 Sep 2010, phoebus phoebus wrote:

> Hi,
> I'm using FPC 2.2.4 with Lazarus.
> The unit eventlog is great for logging events. SO i use it.
> =A0
> My question is how to change the default location for the filename for Li=
nxu =

> ssytem which is harcoded in the code.
> The documentation for TEventLog.FileName wrote:
> " FileName is the name of the log file used to log messages (...). The fi=
le is =

> then located in the "/tmp" directory on unix-like systems, or in the appl=
ication =

> directory for Dos/Windows like systems
> =A0
> Line 56 to 60 from eventlog.inc (fpc\2.2.4\source\packages\fcl-base\src\u=
> =A0=A0=A0 Function TEventLog.DefaultFileName : String;
> =A0=A0=A0 begin
> =A0=A0=A0=A0=A0 Result:=3D'/tmp/'+ChangeFileExt(ExtractFileName(Paramstr(=
> =A0=A0=A0 end;
> I can of course change the function code like Windows to have the log in =
the =

> same directory thtat the application.:
> Line 18 to 22 from eventlog.inc (fpc\2.2.4\source\packages\fcl-base\src\w=
> =A0=A0=A0 Function TEventLog.DefaultFileName : String;
> =A0=A0=A0 begin
> =A0=A0=A0=A0=A0 Result:=3DChangeFileExt(Paramstr(0),'.log');
> =A0=A0=A0 end;
> Could you indicate a nice solution to indicate log file location in using=
 the =

> unit eventlog without change fpc code?

You can just set the filename property, with full path:

It will be created in the path you specify, as you can see in ActivateFileL=

Procedure TEventLog.ActivateFileLog;

   If (FFileName=3D'') then
   // This will raise an exception if the file cannot be opened for writing=
   FStream:=3DTFileStream.Create(FFileName,fmCreate or fmShareDenyWrite);

The default is just that, the default. If you specify a filename, then that
is used. What more do you need ?


More information about the fpc-pascal mailing list