转载请注明出处:https://www.cnblogs.com/coder163/p/9309717.html
https://log4delphi.sourceforge.net/tutorial.html
Log4D下载:
导入Delphi:Tool-->Options-->Environment Options--->Delphi Options--Library-->Library path
三个目录
使用
载入配置文件
菜单--->Project-->View Source
uses Vcl.Forms, TConfiguratorUnit, {需要引用该单元} Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; doPropertiesConfiguration('log4delphi.properties'); { 初始化,读取属性 } Application.CreateForm(TForm1, Form1); Application.Run; end.
拷贝
到exe所在目录
unit Unit2; interface uses TLoggerUnit, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin TLogger.getInstance.debug('Button Clicked!'); end; procedure TForm2.FormDestroy(Sender: TObject); begin TLogger.freeInstances; end; end.
- Compile and run the application. Click the button three times and then exit the application.
- You should have a log file in the tutorial folder named app.log with the following content
DEBUG - Button Clicked
DEBUG - Button Clicked
DEBUG - Button Clicked