EL 2.0 logging not working with root web.config

Topics: Logging Application Block
Feb 27, 2007 at 3:51 AM
My application is configured as a virtual directory within the default web site. The default web site has a web.config and the loggingConfiguration settings is specified within this root web.config. The virtual directory (where my app resides) within the default web site also contains a web.config with loggingConfiguration settings. When i launch my application, it looks like the root web.config settings (in default web site) are being used and not the web.config within the virtual directory. I confirmed this by setting the log category within my code to the one defined in the root web.config and it logs to the db specified in the root web.config. If i set the category to the one defined in my application's web.config it fails to log with the following exception. If i remove the parent web.config then the it logs correctly to the specified db. Has anyone seen this behavior before? Any help will be much appreciated.

The Assembler attribute is not set in the configuration object type
Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.TraceListenerData. 0.163792046195815 0.000385
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.GetAssemblerAttribute(Type type) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\AssemblerBasedObjectFactory.cs:line 100
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.GetAssembler(TConfiguration objectConfiguration) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\AssemblerBasedObjectFactory.cs:line 72
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\AssemblerBasedObjectFactory.cs:line 52
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerCustomFactory.Create(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\TraceListeners\TraceListenerCustomFactory.cs:line 57
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory`2.Create(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\AssemblerBasedCustomFactory.cs:line 63
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerCustomFactory.Create(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache, TraceListenerCache traceListenersCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\TraceListeners\TraceListenerCustomFactory.cs:line 83
at Microsoft.Practices.EnterpriseLibrary.Logging.LogSourceCustomFactory.Create(IBuilderContext context, TraceSourceData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache, TraceListenerCache traceListenersCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\LogSourceCustomFactory.cs:line 53
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\LogWriterStructureHolderCustomFactory.cs:line 61
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\LogWriterCustomFactory.cs:line 46
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\Extensions\ConfiguredObjectStrategy.cs:line 62
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\Strategies\Singleton\SingletonStrategy.cs:line 48
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\Extensions\ConfigurationNameMappingStrategy.cs:line 55
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\BuilderBase.cs:line 101
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\BuilderBase.cs:line 84
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\Program Files\Microsoft Enterprise Library January 2006\src\ObjectBuilder\BuilderBase.cs:line 66
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, IConfigurationSource configurationSource) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\EnterpriseLibraryFactory.cs:line 115
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IConfigurationSource configurationSource) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Common\Configuration\ObjectBuilder\EnterpriseLibraryFactory.cs:line 97
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterFactory.Create() in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\LogWriterFactory.cs:line 52
at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\Logger.cs:line 427
at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(LogEntry log) in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\Logger.cs:line 328
Feb 27, 2007 at 4:36 PM
I recreated the error.

My recommendation is that you only have your logging settings defined in 1 web.config file in your web applications.

The error appears to occur when you have multiple logging configuration settings defined in one or more web.config files in your web application.

If your virtual directory is indeed its own application, I would set it as an application. This will make the virtual directory's web.config file define the logging settings. If it is not its own application, I would remove the logging settings from the virtual directory's web.config file and use the settings in the default website's web.config file.

This is certainly worth adding as an issue so the EntLib Team knows about the problem, however. But I think they expect the logging settings to be defined only once per web application.

Regards,

Dave

_____________________

David Hayden
Microsoft MVP C#
Feb 27, 2007 at 5:56 PM
Edited Feb 27, 2007 at 7:36 PM
Thanks for your response.

Just to clarify, when you say "If your virtual directory is indeed its own application, I would set it as an application." you mean creating a new web site for my application instead of using the virtual directory within default web site right? OR are you referring to the application settings within the virtual directory tab. if that's the case then the application name and other properties are already set when the virtual directory was created. Still you will see the same error.

Yes, the virtual directory is its own application but unfortunately we are in a environment where all the apps should be virtual directories under the default web site. We don't have much control over it. I'm planning not to use the Logger facade and use the LoggerWriter.Write instead and use SystemConfigurationSourceImplementation to pass the config file path. Do you think this will work?

I will add it as an issue but i would imagine since web.config overriding feature is supported, the EL Logging block should be able to handle that as well.

Feb 28, 2007 at 2:42 PM
A virtual directory can be set as its own application or just a directory for another application.

If you set it as its own application, the web.config inside the virtual directory becomes the top-most web.config. If it is part of another application, it is not the top-most web.config because the directory does not represent the root directory of the application.

You can use as many web.config files as you fancy. I think the problem is that the Logging Settings are expected to only be in one web.config file per web application. I am not positive on this, it is based on my work yesterday to re-create your error. The error seems to occur when I have more than one logging configuration defined in a web application.

There may be other reasons, but my guess is that if you only have the logging settings defined once per application your error will go away.

Regards,

Dave

_____________________

David Hayden
Microsoft MVP C#
Feb 28, 2007 at 6:45 PM
Based on my previous analysis, even if i set the virtual directory as its own application within the DefaultWebSite i still see the error. So looks like i will have to either remove the loggingConfiguration from the virtual directory's web.config in which case the root's loggingConfiguration will be used for all logging activities or create a new web site for my application.