Logging as a decorator vs. Dependency Injection - what if I need to log inside the class?

前端 未结 2 1206
太阳男子
太阳男子 2021-02-12 13:11

(I originally asked this question in this comment, but Mark Seemann asked me to create a new question instead.)

I\'m starting a new app (.NET Core, if that matt

2条回答
  •  别那么骄傲
    2021-02-12 14:10

    Don't take SRP so seriously, otherwise you'll end up with functional programming. If you afraid of getting your class cluttered by putting log statements inside it, then you have two options. The first one you already mentioned which is using a Decorator class but you can't access/log the private stuff. The second option is using partial classes and putting the logging statements in a separate class.

提交回复
热议问题