diff --git a/Test/source/MainFrm.pas b/Test/source/MainFrm.pas index 47994c8..d0dfcfa 100644 --- a/Test/source/MainFrm.pas +++ b/Test/source/MainFrm.pas @@ -271,8 +271,25 @@ end; procedure TMainForm.btnCategoryClick(Sender: TObject); + + procedure Category2(ALog: IX2Log); + begin + ALog.Info(edtMessage.Text); + end; + + + procedure Category1(ALog: IX2Log); + begin + ALog.Info('Category 1'); + Category2(ALog.Category('Sub-category')); + ALog.Info('/Category 1'); + end; + + begin - FLog.Category('Test').Info(edtMessage.Text); + FLog.Info('Categories'); + Category1(FLog.Category('Test')); + FLog.Info('/Categories'); end; diff --git a/X2Log.Decorator.pas b/X2Log.Decorator.pas index 27c0151..0d9237b 100644 --- a/X2Log.Decorator.pas +++ b/X2Log.Decorator.pas @@ -8,6 +8,8 @@ uses type + TX2LogCategoryDecoratorClass = class of TX2LogCategoryDecorator; + TX2LogCategoryDecorator = class(TInterfacedObject, IX2Log) private FCategoryName: string; @@ -106,7 +108,7 @@ end; function TX2LogCategoryDecorator.Category(const ACategory: string): IX2Log; begin if Assigned(DecoratedLog) then - Result := Self.Create(DecoratedLog, GetCategory(ACategory)); + Result := (TX2LogCategoryDecoratorClass(Self.ClassType)).Create(DecoratedLog, GetCategory(ACategory)); end;