The assembly process should include the assembly of production with the implementation of unit tests. If this is not the case, you cannot guarantee that someone has not slipped using pragmas (e.g. disconnecting from debug).
What I always do in case of logging, use Log4Net . During development and testing, log messages are set at the most detailed level, and during the production process I try to leave them at the level of errors or information, but should be more detailed if necessary to troubleshoot.
IMO, the best way to accomplish what you are trying to accomplish with SetLogWriter is to actually use an inversion of the control container, such as StructureMap , to assign concrete at runtime based on various configurations. During a unit test, you can use a library like Moq to produce concrete that behaves as expected (an SQL query that always returns the exact same result), although in your particular case you are doing just the opposite (desired logging during unit tests and lack of registration during the manufacturing process).
cfeduke
source share