我有一个 Web 项目(ASP.NET MVC 4 项目),其中存储了许多配置网页配置 and in NLog.config files.
我有几个发布配置文件发布配置文件1, 发布配置文件2当使用发布配置文件将我的 Web 项目部署到服务器时,我想在部署后更改两个配置文件中的许多配置(一些应用程序设置网页配置和一些值NLog.config).
我已按照以下步骤操作here http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx它非常适合更改设置网页配置(例如,从Web.PublishProfile1.Config受到尊重)。
这是我的NLog.PublishProfile1.Config转换文件:
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets >
<target xsi:type="File"
name="tracelog"
fileName="NEW_VALUE_HERE" layout="${longdate} [${threadname}::${threadid}] ${pad:padding=5:inner=${level:uppercase=true}} ${logger} - ${message}"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
</targets>
</nlog>
</nlog>
问题是我有相同的转换NLog.PublishProfile1.config但这些转换在部署后也不会应用。
有谁知道为什么这种转换不适用于 NLog.config 但适用于发布配置文件上的 Web.config?
为了解决这个问题我必须:
1) 避免使用nlog.config
2)创建nlog
里面的部分web.config
并将 nlog.config 的内容移至 web.config,以便能够通过一个文件使用 web.config 转换功能。如需进一步说明,请查看:NLog配置说明 https://github.com/nlog/NLog/wiki/Configuration-file#configuration-file-format
3) 删除xmlns
属性来自于nlog
节点。似乎有一个错误在期间搞乱了一切web.config
转型。您可以安全地删除以下节点:
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4)我找不到一种方法来转换 nlog/targets 节点下的单个目标。要更改记录器的连接字符串,我必须复制整个 xml 节点,在父节点上使用 xdt:Transform="Replace" ,如下所示:
<nlog
throwExceptions="true"
internalLogLevel="Trace"
internalLogFile="..\..\..\Logs\nlog-app.log"
xdt:Transform="Replace">
<!--(copy and paste all nlog configuration here)-->
</nlog>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)