日志框架被注入类框架、日志

2023-09-04 02:17:39 作者:下一个路口

如果一个日志框架被注入到需要它们还是应该每个需要类,它只是知道的框架和直接使用类?我使用log4net的,目前我注射了包装的框架变成需要能够登录类服务,知道日志记录可能不会改变,而且大多数作品需要它,被注入的回答在这个意义上 解决方案

注射更加灵活,从长远来看,因为你可以很容易地有选择地注入到某些地方和禁用日志记录选择,等等。

Should a logging framework be injected into classes that need them or should every class that needs it just know the framework and use it directly? I am using Log4Net and currently I am injecting a service that wraps that framework into the classes that need to be able to log, knowing logging is probably not going to change and that most pieces need it, is injecting the answer in this sense?

解决方案

Injection is more flexible in the long run, since you can easily selectively inject into certain places and disable logging selectively, etc.

 
精彩推荐