.NET动态刷新的app.config [英] .net dynamically refresh app.config

查看:267
本文介绍了.NET动态刷新的app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态地重新加载在.NET Windows应用程序在app.config?我需要打开登录和注销动态而不是仅仅根据在应用程序启动的价值。

How do I dynamically reload the app.config in a .net Windows application? I need to turn logging on and off dynamically and not just based upon the value at application start.

ConfigurationManager.RefreshSection(的appSettings)不工作,我也试着明确使用OpenExeConfiguration打开配置文件,但我总是在应用程序启动时的缓存值,而不是当前值。

ConfigurationManager.RefreshSection("appSettings") does not work and I've also tried explicitly opening the config file using OpenExeConfiguration but I always get the cached value at application startup and not the current value.

我已经接受了创建自定义配置节的答案。作为一个方面说明和愚蠢的错误 - 如果你从IDE中运行有一个在更新app.config文件和预期的变化没有任何意义。宥必须修改的bin \ debug文件夹中.exe.config文件与。卫生署!

I've accepted the answer of creating a custom configuration section. As a side note and foolish mistake - if you're running from the IDE there's no point in updating the app.config file and expecting changes. Yuo have to modify the .exe.config file in the bin\debug folder. Doh!

推荐答案

您可以刷新您自己的部分你说的方式:

You can refresh your own section the way you say:

ConfigurationManager.RefreshSection("yoursection/subsection");

刚刚移动测井真/假成一个部分,你会没事的。

Just move a logging true/false into a section and you'll be fine.

这篇关于.NET动态刷新的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆