log4net configuration - failed to find section

后端 未结 2 1820
生来不讨喜
生来不讨喜 2020-12-10 11:36

This is my error message:

log4net:ERROR XmlConfigurator: Failed to find configuration section \'log4net\' in the application\'s .config file. Check your .con         


        
相关标签:
2条回答
  • 2020-12-10 12:10

    Are you calling XmlConfigurator.Configure() somewhere?

    Remove those calls and only add the [assembly: log4net.Config.XmlConfigurator(Watch = true)] attribute.

    Normally it is easier to configure log4net in a separate file. Create a file log4net.config and change your attribute to:

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

    Remove the section in your web.config.

    0 讨论(0)
  • 2020-12-10 12:17

    Nothing seems wrong with defining the section under <configSections>.

    Try adding [assembly: log4net.Config.XmlConfigurator(Watch = true)] in your AssemblyInfo.cs in the properties folder of your project. This should do the trick in case your configuration is correct under the tag.

    EDIT :

    XmlElement log4NetSection = (XmlElement)ConfigurationManager.GetSection("log4net");
                log4net.Config.XmlConfigurator.Configure(log4NetSection);
    
    0 讨论(0)
提交回复
热议问题