locked
Unable to access the appsettings key if config section is present RRS feed

  • Question

  • User1623378095 posted

    Hi ,

    I am having following config

    <?xml version="1.0"?>
    <configuration>
    <appSettings>
        <add key="IndexPath" value="" />
        <add key="APIUrl" value="http://www.google.com" />
        <add key="Interval" value="3" />
        <add key="ClientSettingsProvider.ServiceUri" value="" />
      </appSettings>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
      </configSections>
      <log4net>
        <root>
          <level value="DEBUG" />
          <appender-ref ref="LogFileAppender" />
        </root>
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <param name="File" value="E:\log-file.txt" />
          <param name="AppendToFile" value="true" />
          <rollingStyle value="Size" />
          <maxSizeRollBackups value="10" />
          <maximumFileSize value="10MB" />
          <staticLogFileName value="true" />
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
        </appender>
      </log4net>  
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
      </startup>
    </configuration>
    When I ma trying to access using ConfigurationManager.AppSettings["APIUrl"].ToString() then it is giving me error ,but if I remove the configsection and log4net section then it works perfect. Please provide me the solution to access appsettings key in the presence of log4net and configsection.
    Thanks ,
    Somnath
    Monday, August 26, 2013 2:10 AM

Answers

  • User1623378095 posted

    sorry ,I was having problem when my appsettings section was beofre configsection .

    After shifting to below Configsection my problem was solved.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 26, 2013 3:12 AM

All replies

  • User-1360095595 posted

    Try moving the appsettings block to be before the configsections block. 

    Monday, August 26, 2013 2:50 AM
  • User1623378095 posted

    sorry ,I was having problem when my appsettings section was beofre configsection .

    After shifting to below Configsection my problem was solved.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 26, 2013 3:12 AM