2012-01-31 2 views
1

Мы недавно перенесли все наши тесты с NUnit на MsTest. Мы используем Spring.NET для контейнера IOC и Log4Net. Log4Net не может найти файл log4net.xml, несмотря на его наличие в тестовом проекте. Есть идеи что это может быть?Как указать Log4net в его файл конфигурации?

Здесь ошибка, что мы получаем:

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

Вот что мы имеем в конфигурационном файле:

<?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> 

ответ

1

Вот фрагмент файла web.config, вот шаги: Вы можете добавить ключ в appSettings, который указывает на внешний файл конфигурации, содержащий все настройки Log4net:

<appSettings> 
     <add key="log4net.Config" value="Configs\develop.config" /> 
    </appSettings> 

Вот внешний конфигурационный файл:

<log4net> 
    <root> 
     <appender-ref ref="LogFileAppender" /> 
    </root> 
    ... 
</log4net> 

В то время как в вашем коде вы будете настроить XmlConfigurator:

Config.XmlConfigurator.Configure(New FileInfo(ConfigurationManager.AppSettings("log4net.Config"))) 
Смежные вопросы