TIniConfiguratorUnit.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. {
  2. Copyright 2005-2010 Log4Delphi Project
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. }
  13. {*----------------------------------------------------------------------------
  14. Contains the configuration procedures used to configure the Log4Delphi
  15. package from a ini file section.
  16. @version 0.5
  17. @author <a href="mailto:vsevolodp@gmail.com">Vsevolod Parfenov</a>
  18. ----------------------------------------------------------------------------}
  19. unit TIniConfiguratorUnit;
  20. interface
  21. uses
  22. Classes, SysUtils, IniFiles,
  23. TPropertiesUnit, TPropertyConfiguratorUnit, TLogLogUnit;
  24. procedure DoConfigure(const AFilename, ASectionName : String);
  25. implementation
  26. procedure DoConfigure(const AFilename, ASectionName : String);
  27. var
  28. props : TProperties;
  29. fin : TIniFile;
  30. sl: TStringList;
  31. i: Integer;
  32. value: String;
  33. begin
  34. props := TProperties.Create;
  35. fin := TIniFile.Create(AFilename);
  36. sl := TStringList.Create();
  37. try
  38. try
  39. fin.ReadSection(ASectionName, sl);
  40. for i := 0 to sl.Count - 1 do
  41. begin
  42. value := fin.ReadString(ASectionName, sl[i], '');
  43. props.SetProperty(sl[i], value);
  44. end;
  45. TPropertyConfiguratorUnit.DoConfigure(props);
  46. except
  47. on E: Exception do begin
  48. TLogLog.error('Could not read configuration file ['
  49. + AFileName + '] ' + e.Message);
  50. TLogLog.error('Ignoring configuration file [' + AFilename + ']');
  51. end;
  52. end;
  53. finally
  54. props.Free;
  55. fin.Free;
  56. sl.Free;
  57. end;
  58. end;
  59. end.