locked
third party logging config RRS feed

  • Question

  • User37182867 posted

    I'm working with a third party that uses EnterpriseLibrary for logging. I have a website set up that everything works fine on but when I set up a unit testing project I get the (Activation error occured while trying to get instance of type LogWriter, key "") error message. I have researched and found that this is likely a configuration error and have copied all the relevant enterprise library config settings from the web project to the unit testing project. They have 6 config files that are linked from the web.config file and I have all of those config files in the unit testing project as well. Still getting the same error. 

    References in the web project and unit testing project are the same. Config sections were copied over. I've deleted everything and started over twice now and no changes.

    Any suggestions would be appreciated.

    Stack Trace is as follows.

    Microsoft.Practices.ServiceLocation.ActivationException was caught
      HResult=-2146233088
      Message=Activation error occured while trying to get instance of type LogWriter, key ""
      Source=Microsoft.Practices.ServiceLocation
      StackTrace:
           at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
           at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
           at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
           at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message, String category)
           at Diamond.Common.Diagnostics.DebugUtils.WriteToDebug(String text)
           at Diamond.Common.Diagnostics.DebugUtils.RawTraceHelper(String text, Boolean newLine, Boolean showThread)
           at Diamond.Common.Diagnostics.DebugUtils.BenchmarkTrace(String text)
           at Diamond.Common.Diagnostics.Benchmark..ctor(String callingClass, String callingMethod, String benchmarkAlias, Boolean startTraceMessage, String addtionalText)
           at Diamond.Common.Services.Proxies.ProxyBase.Execute[T,Y](T request, String methodName)
           at Diamond.Common.Services.Proxies.LoginServiceProxy.GetDiamTokenForUsernamePassword(Request request)
           at IFM.DiamondServices.Services.Diamond.Login.Login._Closure$__741._Lambda$__741(RequestBase a0)
           at IFM.DiamondServices.Services.Common.Common.RunDiamondService(pMethod& m, RequestBase req, Exception& e, DiamondValidation& dv)
      InnerException: Microsoft.Practices.Unity.ResolutionFailedException
           HResult=-2146233088
           Message=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.
    -----------------------------------------------
    At the time of the exception, the container was:
    
      Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
    
           Source=Microsoft.Practices.Unity
           TypeRequested=LogWriter
           StackTrace:
                at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
                at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides)
                at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
                at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
                at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
           InnerException: System.InvalidOperationException
                HResult=-2146233079
                Message=The type LogWriter cannot be constructed. You must configure the container to supply this value.
                Source=Microsoft.Practices.Unity
                StackTrace:
                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)
                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)
                     at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                     at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
                InnerException: 
    

    Friday, February 20, 2015 10:43 AM

Answers

  • User37182867 posted

    Solved.

    As the normal issue with this error is not being able to read the config files correctly this was part of the issue. We were missing 2 config files. The rest of the issue was resolved when we instantiated an HttpContext from the Unit test project. The missing configs let enterprise logging function and then function itself needed a session object.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2015 10:07 AM