Windows 服务配置文件 C# [英] Windows Service Config File C#
问题描述
我使用 Visual Studio 2008/C# 开发了一个 Windows 服务应用程序.
I've developed a windows service application using Visual Studio 2008 / C#.
我在项目中有一个 app.config 文件.安装后,app.exe.config 文件出现在可执行文件旁边,但当我尝试通过 ConfigurationManager.AppSettings 访问它们时,它似乎没有从中读取值.
I have an app.config file in the project. When installed, the app.exe.config file appears beside the executable but it appears not to be reading the values from it when I try to access them through ConfigurationManager.AppSettings.
它是否将配置文件复制到了别处,还是有其他一些我不知道的问题?
Has it copied the config file elsewhere or is there some other problem I don't know about?
提前致谢,
马丁.
配置文件名实际上是 my_exe_file_name.exe.config,它看起来像:
The config file name is infact my_exe_file_name.exe.config, it looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="RuntimeFrequency" value="3" />
</appSettings>
</configuration>
我正在尝试通过以下方式阅读:
and I am trying to read via:
ConfigurationManager.AppSettings["RuntimeFrequency"]
我不断看到的调试值是1"而不是3".我在这里做错了吗?
The debug value I continually see is '1' and not '3'. Am I doing something wrong here?
推荐答案
我找到了错误,它与文件权限有关.安装该服务后,我的本地用户帐户无权修改 app.exe.config 文件.
I located the error and it was related to file permissions. After installing the service, my local user account didn't have access to modify the app.exe.config file.
我用来编辑的工具没有通知我它被拒绝访问以保存文件 - 如果有人感兴趣,那就是记事本++ - 所以我看不出它没有保存在旧的配置文件上.
The tool I was using to edit was not informing me it was being denied access to save the file - that's notepad++ if anyone is interested - so I couldn't see that it wasn't saving over the old config file.
现在解决了,谢谢大家.
Solved now, thanks everyone.
马丁.
这篇关于Windows 服务配置文件 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!