.NET服务的user.config位于何处?

问题描述 投票:3回答:2

我正在使用installutil.exe. (.NET 4.0)安装基于.NET的Windows服务。此服务包括ServiceName.exe.config file。此文件与.exe文件本身存储在同一目录中。但似乎该文件只保留默认值(如“标准”.NET应用程序)。在服务运行时更改设置不会在安装路径中的ServiceName.exe.config中生效(作为http://stackoverflow.com/questions/17154936/net-service-config-file-locationother的答案)类似的问题建议)。在C:\Windows\Users\"Username"\AppData\Local\看也没有带来成功。

更改设置正在运行,我通过将一些设置值写入日志文件来检查。唯一的问题是,存储值的文件和位置在哪个位置?

编辑:

配置文件看起来像这样。

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="MeLoQDASExportService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="MeLoQDASExportService.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.0,Profile=Client"/>
    </startup>
    <applicationSettings>
        ...
    </applicationSettings>
    <userSettings>
        <MeLoQDASExportService.Properties.Settings>
            <setting name="logName" serializeAs="String">
                <value>ExportLog.txt</value>
            </setting>
            <setting name="lastExport" serializeAs="String">
                <value>1990-01-01</value>
            </setting>
        </MeLoQDASExportService.Properties.Settings>
    </userSettings>
</configuration> 

这是已安装服务的文件夹中的文件。它仍包含初始值,但是从服务到文本文件的值的输出显示实际值(例如“lastExport”的当前日期)

c# .net service settings
2个回答
0
投票

尝试System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel level)http://msdn2.microsoft.com/en-us/library/ms134265.aspx

传递ConfigurationUserLevel.PerUserRoamingAndLocal(或者也尝试PerUserRoaming)。然后在返回的Configuration对象上,获取FilePath属性。


0
投票

我刚刚发现使用Process Monitor

C:\ WINDOWS \ Syswow64资料\ CONFIG \ systemprofile \应用程序数据\

© www.soinside.com 2019 - 2024. All rights reserved.