We recently moved all our tests from NUnit to MsTest. We are using Spring.NET for an IOC container and Log4Net. Log4Net is unable to find the log4net.xml despite having it in test project. Any ideas what it could be?
Here is the error that we are receiving:
Unable to create instance of class
OurCompany.DataAccess.DocumentManagement.Tests.EmailVerificationTokensAdapterTests.DeleteTests.
Error: Common.Logging.ConfigurationException: Unable to create
instance of type Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter.
Possible explanation is lack of zero arg and single arg
NameValueCollection constructors —>
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. —>
Common.Logging.ConfigurationException: log4net configuration file
‘log4net.xml’ does not exists. at
Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter..ctor(NameValueCollection
properties)
— End of inner exception stack trace — at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo
method, Object[] args, ref SignatureStruct signature, RuntimeType
declaringType) at
System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo
method, Object[] args, SignatureStruct signature, RuntimeType
declaringType) at
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes) at System.Activator.CreateInstance(Type type,
BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo
culture, Object[] activationAttributes) at
Common.Logging.LogManager.BuildLoggerFactoryAdapter()
— End of inner exception stack trace — at Common.Logging.LogManager.BuildLoggerFactoryAdapter() at
Common.Logging.LogManager.get_Adapter() at
Spring.Testing.Microsoft.AbstractSpringContextTests..ctor() at
Spring.Testing.Microsoft.AbstractTransactionalDbProviderSpringContextTests..ctor()
at
OurCompany.Tests.Common.Domain.SATransactionalIntegrationTestsBase..ctor()
in SATransactionalIntegrationTestsBase.cs: line 19 at
OurCompany.DataAccess.DocumentManagement.Tests.EmailVerificationTokensAdapterTests.DeleteTests..ctor()
in DeleteTests.cs: line 20
Here is what we have in the config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="All" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
Here’s a snippet of the
web.configfile, here’s the steps:You can add a key in the
appSettingsthat points to an external config file containing all the Log4net settings:Here’s the external config file:
While in your code you will setup the
XmlConfigurator: