Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is wrapping log4net to reduce coupling an antipattern?

Is wrapping log4net to reduce coupling an antipattern? Or injecting the logger instance into a public property an antipattern? How do you approach the log4net dependency?

like image 923
Oscar Cabrero Avatar asked Dec 05 '25 15:12

Oscar Cabrero


1 Answers

Wrap a logger for below reasons -

  1. It isolates the change only to logger, in future if you want to change it to something better no cascaded changes.
  2. It makes your life easy when you want to write the test cases. You can easily mock the stuff required.
  3. If due to certain reasons you need to have more than one logger in your app, then wrapper helps. You can change the logger through some factory / registry. Ex - if a code is shared among different platforms/environments where you want to have different logger. You can make it factory/registry driven.

So, my view is good to wrap it.

like image 188
JustCode Avatar answered Dec 07 '25 05:12

JustCode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!