2013-07-04 12 views
13

Dies ist meine Fehlermeldung zu finden:log4net-Konfiguration - nicht bestandenen Abschnitt

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 

das ist mein web.config: mit dem Config

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
    </configSections> 

    <system.serviceModel> 
    ... 
    </system.serviceModel> 

    <connectionStrings> 
    ... 
    </connectionStrings> 

    <log4net> 
    ... 
    </log4net> 

</configuration> 

Was ist falsch?

Update:

Haben auch Web.Release.config:

<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 

    <system.web> 
     <compilation xdt:Transform="RemoveAttributes(debug)" /> 
    </system.web> 

    <system.serviceModel> 
    ... 
    </system.serviceModel> 

    <connectionStrings> 
    ... 
    </connectionStrings> 

    <log4net> 
    ... 
     <root> 
      <level value="DEBUG" xdt:Transform ="Replace"/> 
     </root> 
    </log4net> 

</configuration> 

Web.Test.cofig - das gleiche wie Veröffentlichung einer

und Web.Debug.config, dass ist leer:

<?xml version="1.0"?> 

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  

</configuration> 
+0

Ich habe diese Fehlermeldung, aber mein Logger funktioniert gut. – MikroDel

Antwort

5

Nichts scheint falsch mit def den Abschnitt unter <configSections>.

Versuchen Sie, [assembly: log4net.Config.XmlConfigurator(Watch = true)] in Ihrer AssemblyInfo.cs im Eigenschaftenordner Ihres Projekts hinzuzufügen. Dies sollte ausreichen, falls Ihre Konfiguration unter dem Tag korrekt ist.

EDIT:

XmlElement log4NetSection = (XmlElement)ConfigurationManager.GetSection("log4net"); 
      log4net.Config.XmlConfigurator.Configure(log4NetSection); 
+0

danke für deine Antwort Siraj. Versuchte es und nichts ist passiert - die gleiche Fehlermeldung – MikroDel

+0

Überprüfen Sie meine Edit und versuchen Sie dieses Stück Code auf Ihrem "AppStart" oder die Punktausführung beginnt auf Ihrer Anwendung –

+0

Vergessen Sie nicht, Verweis auf die System.Configuration Assembly hinzuzufügen. und add "using System.Configuration" –

17

Sie XmlConfigurator.Configure() irgendwo nennend?

Entfernen Sie diese Anrufe und fügen Sie nur das Attribut [assembly: log4net.Config.XmlConfigurator(Watch = true)] hinzu.

Normalerweise ist es einfacher, log4net in einer separaten Datei zu konfigurieren. Erstellen Sie eine Datei log4net.config und ändern Sie Ihr Attribut:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)] 

Entfernen Sie den Abschnitt in Ihrem web.config.

+0

"Rufen Sie XmlConfigurator.Configure() irgendwo auf?" - nein – MikroDel

+0

Das hat funktioniert. Ich nehme an, XmlConfigurator.Configure() wird nicht mehr benutzt ?? So habe ich es immer gemacht. Ich musste nie die Assembly.cs ändern. Ich lese besser die neueste Dokumentation. –

Verwandte Themen