You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "William R. Daniels, Jr." <bi...@gmcps.com> on 2004/11/18 21:24:16 UTC

DomConfigurator error and Assembly woes

My application runs in .Net1.1SP1 as a consoleapplication project with a
separate classlibrary project.

I would like to instantiate a logger in each of 2 classes in the
classlibrary.  The classlibrary has a reference to the log4net.dll in
another library folder. A sample class1.vb looks like (and class2.vb
looks strikingly similar):

Public Class Class1
    Private ReadOnly log As log4net.ILog = _
 
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMeth
od().DeclaringType)
    Sub LogMessage()
        log.Debug("Message from Class1")
    End Sub
End Class


The one module inside the ConsoleApplication project (which also
references the log4net.dll) looks like:

' <Assembly: log4net.Config.DOMConfigurator()> 

Module Module1

    Sub Main()
        Dim MyClass1 As New Class1
        Dim MyClass2 As New Class2
        log4net.Config.DOMConfigurator.Configure()
        MyClass1.LogMessage()	
        MyClass2.LogMessage()
    End Sub

End Module

And the app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Register a section handler for the log4net section -->
	<configSections>
			<!-- <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" /> -->
			<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
			<!-- <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net,
Version=1.2.0.30714, Culture=neutral, PublicKeyToken=b32731d11ce58905"
/> -->
	</configSections>
	<appSettings>
		<!-- To enable internal log4net logging specify the
following appSettings key -->
		<add key="log4net.Internal.Debug" value="true"/>
	</appSettings>
	
	<!-- This section contains the log4net configuration settings
-->
	<log4net>
		<!-- Define some output appenders -->
		
		<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
			<layout type="log4net.Layout.PatternLayout">
				<param name="ConversionPattern"
value="%d [%t] %-5p %c - %m%n" />
			</layout>
		</appender>
		
		<!-- Setup the root category, add the appenders and set
the default level -->
		<root>
			<level value="ALL" />
			<appender-ref ref="ConsoleAppender" />
		</root>
	</log4net>
</configuration>

These errors appear when MyClass1 is instantiated:

log4net: log4net assembly [log4net, Version=1.2.0.30714,
Culture=neutral, Public
KeyToken=b32731d11ce58905]. Loaded from [Global Assembly Cache]. (.NET
Runtime [
1.1.4322.2032] on Microsoft Windows NT 5.1.2600.0)
log4net: DefaultRepositorySelector: defaultRepositoryType
[log4net.Repository.Hi
erarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly
[ClassLibra
ry, Version=1.0.1783.20199, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [ClassLibrary,
Version=1.0.1783.201
99, Culture=neutral, PublicKeyToken=null] Loaded From [c:\documents and
settings
\bill.gmcps\my documents\visual studio
projects\oologging\consoleapplication1\bi
n\classlibrary.dll]
log4net: DefaultRepositorySelector: Assembly [ClassLibrary,
Version=1.0.1783.201
99, Culture=neutral, PublicKeyToken=null] does not have a
DomainAttribute specif
ied.
log4net: DefaultRepositorySelector: Assembly [ClassLibrary,
Version=1.0.1783.201
99, Culture=neutral, PublicKeyToken=null] using domain
[log4net-default-domain]
and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for domain
[log4net-defa
ult-domain] using type [log4net.Repository.Hierarchy.Hierarchy]

The same basic errors appeared when I tried to use the Assembly:
DOMconfigurator.  The assembly doesn't seem to be used until the log
interface is instantiated within the class.  I'm not surprised by the
errors since the classlibrary is not associated with the .config file.

These errors appear when log4net.Config.DOMConfigurator.Configure() is
invoked:

log4net: DefaultRepositorySelector: Creating repository for assembly
[ConsoleApp
lication1, Version=1.0.1783.20199, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1,
Version=1.0.1
783.20199, Culture=neutral, PublicKeyToken=null] Loaded From
[C:\Documents and S
ettings\bill.GMCPS\My Documents\Visual Studio
Projects\OOLogging\ConsoleApplicat
ion1\bin\ConsoleApplication1.exe]
log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1,
Version=1.0.1
783.20199, Culture=neutral, PublicKeyToken=null] does not have a
DomainAttribute
 specified.
log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1,
Version=1.0.1
783.20199, Culture=neutral, PublicKeyToken=null] using domain
[log4net-default-d
omain] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: domain [log4net-default-domain]
already exis
its, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DOMConfigurator: configuring repository
[log4net-default-domain] using
.config file section
log4net: DOMConfigurator: Application config file is [C:\Documents and
Settings\
bill.GMCPS\My Documents\Visual Studio
Projects\OOLogging\ConsoleApplication1\bin
\ConsoleApplication1.exe.config]
log4net:ERROR DOMConfigurator: Failed to parse config file. Is the
<configSectio
ns> specified as: <section name="log4net"
type="log4net.Config.Log4NetConfigurat
ionSectionHandler,log4net, Version=1.2.0.30714, Culture=neutral,
PublicKeyToken=
b32731d11ce58905" />
System.Configuration.ConfigurationException: Could not create
log4net.Config.Log
4NetConfigurationSectionHandler, log4net
   at System.Configuration.ConfigurationRecord.GetFactory(String
configKey)
   at System.Configuration.ConfigurationRecord.Evaluate(String
configKey)
   at System.Configuration.ConfigurationRecord.ResolveConfig(String
configKey)
   at System.Configuration.ConfigurationRecord.GetConfig(String
configKey)
   at
System.Configuration.DefaultConfigurationSystem.System.Configuration.ICo
nf
igurationSystem.GetConfig(String configKey)
   at System.Configuration.ConfigurationSettings.GetConfig(String
sectionName)
   at log4net.Config.DOMConfigurator.Configure(ILoggerRepository
repository)

Things work as I hope IFF I use the long fully spec'd version of the
Log4NetConfigurationSectionHandler config but none of the examples I can
find on the web show that anyone else has to do that.  I would have to
revise all of my .config files each time a new log4net assembly is
generated if I went that route.

So my ultimate, final question is "How can I call the
DOMconfigurator.Configure() with the short
Log4NetConfigurationSectionHandler config line so that my logger
interfaces in the classes work properly?"

Thanks,

Bill Daniels
Green Mountain Consulting
901.507.9326
bill@gmcps.com
www.greenmountainconsulting.com