【发布时间】:2018-03-06 19:38:42
【问题描述】:
我的服务中有一个方法,我正在查看服务配置文件。它看起来像这样:
private void WatchConfigurationFile()
{
var fileLocation = Assembly.GetExecutingAssembly().Location;
watcher.Path = Path.GetDirectoryName(fileLocation);
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = fileLocation + ".config";
watcher.Changed += new FileSystemEventHandler(OnConfigChange);
watcher.EnableRaisingEvents = true;
Log.DebugFormat("config location: {0}", watcher.Filter.ToString());
}
日志返回我的目标文件的完整文件路径位置,包括它的存储位置:C/Users等
然而,当我更新我的配置文件时,更改不会显示在我的日志文件中。日志记录是这样完成的:
private void OnConfigChange(object source, FileSystemEventArgs e)
{
ConfigurationManager.RefreshSection("appSettings");
Log.DebugFormat("Updated ConnectionString: {0}", ConfigurationManager.AppSettings["dbConn"]);
}
但是,在我的文件观察程序类中,如果我将过滤器更改为文件的实际名称,在我的情况下,它是服务 exe 名称,末尾带有“.config”。它工作正常。
为什么一个有效而另一个无效?
【问题讨论】:
-
可能是 (app_name).vshost.exe.config 也需要更新?
标签: c# string file-watcher