Remove logging code dependency

I seem more like a question because I am refactoring a fairly large part of the code that I took over.

It is not modular, it is mostly pseudo object-oriented code. It contains hard-coded dependencies, lack of interfaces, many responsibilities, etc. Just chaos .

In addition, it contains many internal calls of the Audit class , which contains methods such as Log, Info, LogError , etc. This class must be configured in the application configuration to work, otherwise it will fail. And this is the main pain for me. And please allow me to focus on this problem in the answers, namely to make the client code independent of the classes / solutions / registration frameworks .

And now, I would like these classes to have a hard encoding of the Audit class , reorganized to provide several advantages:

  • First of all, you need to extract them into different assemblies, since I need some functionality available in other applications (for example, creating attachment code - call the AttachmentsGenerator class , which until now was specyfic for one application, but now this code can use in many places)
  • Remove internal dependencies so that another application uses my AttachmentsGenerator class without the need to add references to other
  • Do a magic trick to let the AttachmentsGenerator class report some audit information, traces, etc. But I do not want this to be a hard-coded implementation. In fact, I do not want this to be mandatory, so I could use AttachmentsGenerator without setting up internal logging and without the need for the client code to add a link to other assemblies to use logging. Bottom line: if the client code wants to use the AttachmentsGenerator , it adds a reference to the assembly that contains this class, and then uses the new statement and that's it.

.. ? , , . //.

, Paweł

1: , : , ?

+3
2

, - .

  • ILogger .

  • ILogger, (, NullLogger)

  • , , (, log4net)

  • DI (spring, ..), , .

+4

( ) Decorator. , SOLID, ILogger ( DRY).

+3

All Articles