开发者

Injecting an ILog with MEF and a GuyWire

While learning to crawl with DI tools, I am hoping someone can help me apply some concepts to a relatively simple scenario:

* Log4NetLogger : ILogger  
* DebugLogger : ILogger  
* NullLogger  : ILogger (no output: saves time & noise)  

when my application is running, I want an ILog to be a Log4NetLogger, and when unit testing I want it to be either a DebugLogger or a NullLogger.

I have been looking at a GuyWire implementation that I like, which uses WindsorInstallers. Not being biased towards a开发者_运维百科ny other DI tool and understanding the installer concept if not many of the nuances, Windsor seems as good as any other container.

So, would I have a ProductionLoggingInstaller that wires up Log4Net and a TestLoggingInstaller otherwise? How about switching tests to be either to DebugLogger or NullLogger?

And then there is MEF, which I get just enough at this point to think it can either solve this 'problem' also, but not sure if that would be without any container or in addition to the contain.

So how would you apply some combination of a GuyWire, Windsor, and or MEF to solve the logging resolution scenario here?

Cheers,

Berryl

NOTE: I am specifically using this logging scenario to apply some dependency injection tools (ie, MEF, Windsor, GuyWire, etc), as opposed to app.config of specific logging tool


You can solve the different behavior from production and test by changing te configuration portion. Any well based logger should provide a comprensive suite of appenders ( even a null appender ) and leave the IoC responsible of choosing the engine, not how the engine itself is configured.


Take a look a Common Log (http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html). It allows you to code to one interface and then change loggers via the config file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜