如何在c#winforms中的app.config文件上动态更新应用程序设置键值对

vij*_*esh 5 c# appsettings winforms

如何在c#winforms中的app.config文件上动态更新应用程序设置键,值.键,值列在下面

<appSettings>
    <add key="logPath" value="C:\EventLogs" />
    <add key="isScreenCaptureMode" value="false" />
    <add key="isStartOnSysStartUp" value="false" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

vij*_*esh 8

Configuration configuration = ConfigurationManager.
OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
configuration.AppSettings.Settings["logPath"].Value = DateTime.Now.ToString("yyyy-MM-dd");
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");
Run Code Online (Sandbox Code Playgroud)