delphi xe 好用的日誌框架

redhat588發表於2024-03-09

選單:Project-->Options-->Search Path引入地址

如:E:\Software\DelphiLib\loggerpro_1_3_1

interface

uses
  LoggerPro,
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.StdCtrls,
  Vcl.ComCtrls;

type
  TfrmCallYFDemo = class(TForm)
    btn1: TButton;
    stat1: TStatusBar;
    grpLog: TGroupBox;
    mmoLog: TMemo;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FLog: ILogWriter;
    { Private declarations }
  public
    function Log: ILogWriter;
  end;
uses
  //LoggerPro.GlobalLogger,
  LoggerPro.VCLMemoAppender,
  LoggerPro.FileAppender,
  //LoggerPro.VCLListViewAppender,
  System.Win.ComObj;

procedure TfrmCallYFDemo.FormCreate(Sender: TObject);
begin
  FLog := BuildLogWriter([TVCLMemoLogAppender.Create(mmoLog,100,False,'%0:s [%2:s]  %3:s  [%4:s]'),TLoggerProFileAppender.Create(5,1000,'log')]);
  log.info('日誌框架載入成功!','FormCreate');
end;

function TfrmCallYFDemo.Log: ILogWriter;
begin
  Result := FLog;

end;

相關文章