无法使用 Properties.Settings 从 app.config 中读取

Can't read from app.config using Properties.Settings

我正在尝试从我的 AppConfig 中读取,但它不工作。

App.Config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="Console.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<userSettings>
    <Console.Properties.Settings>
        <setting name="LogFiles" serializeAs="String">
            <value>True</value>
        </setting>
    </Console.Properties.Settings>
</userSettings>
</configuration>

Program.cs:

namespace Console
{
class Console
{
    public static readonly bool LogFiles = Properties.Settings. //Cant find symbol Default
    static void Main(string[] args)
    {
        //Do stuff here
    }
}
}

使用 Properties.Settings 时,我找不到默认符号或日志文件 属性。我错过了什么?

实现此目的的惯用方法是使用 ConfigurationManager.AppSettings[key]。配置将如下所示:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <appSettings>
    <add key="LogFiles" value="True" />
  </appSettings>
</configuration>

应用程序设置的检索将是:

bool logFiles = Convert.ToBoolean(ConfigurationManager.AppSettings["LogFiles"]);