Unable to Inject References, Issue with LogWriter

Topics: Enterprise Library Core, General discussion, Logging Application Block
Sep 27, 2010 at 1:54 PM

Hello,

When I try to use Unity for DI purposes, I'm getting this error:

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type LogWriter, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".Exception occurred while: while resolving.Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.

My question is, why do I have to have a LogWriter?  Is it required?

Thanks.

Sep 27, 2010 at 3:38 PM

What you you doing? It's trying to inject a LogWriter because somewhere in your object graph is a requirement for one. Without any more information it's hard to answer your question. First off, which version of Entlib / Unity are you using? How are you initializing the container? Are you sure the config file you're using is the one you think it's using?

 

Sep 27, 2010 at 4:39 PM

Nevermind, I figured it out; I was assuming Logger.IsLoggingEnabled would check whether the LogWriter existed first, but it doesn't it assumes the LogWriter exists... checking if (LogWriter == null) return false; would be a plus :-)

Thanks.