NLog上的配置转换不起作用 [英] Config Transformation on NLog does not work
问题描述
我有一个Web项目(ASP.NET MVC 4项目),该项目的许多配置存储在 Web.Config 和 NLog.config 文件中。
I have a web project (ASP.NET MVC 4 project) that has a number of configurations stored in Web.Config and in NLog.config files.
我有几个发布配置文件 PublishProfile1 , PublishProfile2 等。使用发布配置文件将我的Web项目部署到服务器上,我想在部署后从两个配置文件中更改一些配置( Web.config 中的某些应用程序设置,以及 NLog.config 中的某些值)。
I have several publish profiles PublishProfile1, PublishProfile2 etc. When using a publish profile to deploy my web project to a server, I want to change a number of configs from both config files after deploy (some App Settings in Web.config and some values in NLog.config).
我已经从此处进行了操作,它非常适合更改 Web.Config 中的设置(例如,尊重 Web.PublishProfile1.Config 的转换)。
I have followed the steps from here and it works perfectly for changing the settings in Web.Config (e.g. the transformations from Web.PublishProfile1.Config are respected).
这是我的 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的线索吗?
Does anyone has a clue on why this transformation does not work for NLog.config but works ok for Web.config on a publish profile?
推荐答案
要解决此问题,我必须:
To solve this issue I had to:
1)避免使用 nlog.config
2)创建 nlog
部分,然后将nlog.config的内容移动到web.config以便能够将web.config转换功能与一个文件。有关更多说明,请查看: NLog配置说明 web.config
内的
3)从 nlog
xmlns 属性>节点。在 web.config
转换期间,似乎有一个使所有内容混乱的错误。您可以安全地删除以下节点:
3) Remove xmlns
attributes from the nlog
node. There seems to be a bug that messes everything during the web.config
transformation. You can safely remove the following nodes:
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,如下所示:
4) I couldn't find a way to transform just a single target under nlog/targets node. To change the connection string of my logger, I had to copy the whole xml node, using a xdt:Transform="Replace" on the parent node like the following:
<nlog
throwExceptions="true"
internalLogLevel="Trace"
internalLogFile="..\..\..\Logs\nlog-app.log"
xdt:Transform="Replace">
<!--(copy and paste all nlog configuration here)-->
</nlog>
这篇关于NLog上的配置转换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!