views:

72

answers:

3

I'm trying to get fluent configuration working without success. I get the following error:

Activation error occured while trying to get instance of type LogWriter, key ""

when I try to access the logwriter:

Dim logwriter As LogWriter = EnterpriseLibraryContainer.Current.GetInstance(Of LogWriter)()

Configuration:

    Dim formatBuilder As New FormatterBuilder()
    Dim builder As New ConfigurationSourceBuilder()
    builder.ConfigureInstrumentation().EnableLogging()
    builder.ConfigureLogging.LogToCategoryNamed("Important") _
        .WithOptions.SetAsDefaultCategory() _
        .SendTo.RollingFile("StandardListener") _
                .RollEvery(RollInterval.Midnight) _
                .RollAfterSize(50000) _
                .WhenRollFileExists(RollFileExistsBehavior.Increment) _
        .FormatWith(formatBuilder.CustomFormatterNamed("StandardFormatter", GetType(StandardFormatter))) _
        .ToFile("D:\LogFiles\" + fileName)
A: 

I think the issue is with "Of LogWriter" try changing to:

Dim logwriter As LogWriter = EnterpriseLibraryContainer.Current.GetInstance(Of MyProgram)()
Lucas B
ehh. How would that work? What is "MyProgram"? "Of LogWriter" means that I want to get an object of type LogWriter.
jgauffin
I see what you are saying now... Log4Net requires you pass in your local class name, have you tried working through http://msdn.microsoft.com/en-us/library/ff664535(PandP.50).aspx
Lucas B
Have you read that page? Exactly what on that page would help me?
jgauffin
Yes, which is why I see what you were saying. :)Do you have everything setup in your app.config? Did you start with a "hello world" application that wrote to the log? Or this walkthrough might be helpful: http://davidhayden.com/blog/dave/archive/2006/02/15/2802.aspx
Lucas B
ehhh, in my config? Fluent configuration is an alternative to app.config.
jgauffin
A: 

Couldn't get it to work with Unity. Using logwriters static methods work with the fluent configuration though.

jgauffin
+1  A: 

What do you actually DO with the configuration once you're done with it? Have you put it into a configuration source and fed it to a container or to Entlib?

Your configuration looks ok at first glance, but that just builds the object graph. You need something like this afterwards:

  dim configSource as new DictionaryConfigurationSource()
  builder.UpdateConfigurationSourceWithReplace(configSource)
  ' To use container directly
  dim container as IUnityContainer = new UnityContainer() _
    .AddExtension(New EnterpriseLibraryCoreExtension(configSource))

  ' Or, to use Entlib static APIs
  EnterpriseLibraryContainer.Current = EnterpriseLibrary.CreateDefaultContainer(configSource)

That should do it. If it doesn't, please post a more detailed example and I can probably debug it for you.

Chris Tavares