开发者

How to map entlib.config on a webservices webconfig with relative path?

it seems that if I don't give the correct path (i.e. c:\something\entlib.config) I get the following error when running the webservice:

System.IO.FileNotFoundException: The configuration file Entlib.config could not be found. (...)

This is the Webconfig part that r开发者_运维问答efers to the entlib file:

<enterpriseLibrary.ConfigurationSource selectedSource="EntLibconfig" parentSource="">
<sources>
  <add name="EntLibconfig"
       type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       filePath="Entlib.config" />
</sources>
</enterpriseLibrary.ConfigurationSource>

I've tried several combinations already filePath="Entlib.config" /> filePath=".\Entlib.config" /> filePath="~\Entlib.config" /> filePath=".\Entlib.config" /> filePath="~\Entlib.config" />


I believe this was a bug introduced in version 5. It looks like it is fixed in Microsoft Enterprise Library 5.0 Optional Update 1.

Or you could extend FileConfigurationSource and override the CreateSource method (as in the bug report comments above).


If you are using a Project setyp folder then you can add a custom Project Installer file, then after the install has completed you can find the entlib.config file because you know from the installer where the files were installed and then open the entlib.config and replace the current path with the installed path.

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
    {
        //Gets Installed Directory that user selected
        string installDirectory = Path.GetDirectoryName(Context.Parameters["assemblypath"]);


        string[] lines = File.ReadAllLines(installDirectory + "\\NLog.config");
        File.Delete(installDirectory + NLOGFILE);
        StreamWriter sw = File.AppendText(installDirectory + "\\NLog.config");
        foreach (string line in lines)
        {
            if (line.Contains("LOGS"))
            {
                string logDir = line.Replace("LOGS", installDirectory + "\\LOGS");
                sw.WriteLine(logDir.Replace('\\', '/'));
            }
            else
            {
                sw.WriteLine(line);
            }
        }
        sw.Flush();
        sw.Close();
    }

I do something similar with Nlog.config.
Update
"The path can be a relative or absolute path." Please see this link for further details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜