日志框架被注入类 [英] Logging framework being injected into classes

查看:140
本文介绍了日志框架被注入类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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

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.

这篇关于日志框架被注入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆