Tam*_*nut 15 deployment xslt asp.net-mvc web-config nlog
我有一个Web项目(ASP.NET MVC 4项目),它有许多配置存储在Web.Config和NLog.config文件中.
我有几个发布配置文件PublishProfile1,PublishProfile2等.当使用发布配置文件将我的Web项目部署到服务器时,我想在部署后更改两个配置文件中的一些配置(Web.config中的一些应用程序设置和一些值NLog.config).
我已经按照这里的步骤进行操作,它非常适合更改Web.Config中的设置(例如,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>
Run Code Online (Sandbox Code Playgroud)
问题是我在NLog.PublishProfile1.config中有相同的转换,但是在部署之后也不会应用这些转换.
有没有人知道为什么这个转换对NLog.config不起作用但对发布配置文件中的Web.config有效?
Már*_*les 24
要解决这个问题,我必须:
1)避免使用nlog.config
2)在web.config中创建nlog部分,并将nlog.config的内容移动到web.config,以便能够将web.config转换功能与一个文件一起使用.要进一步说明,请查看:NLog配置说明
3)从nlog节点中删除xmlns属性.似乎有一个错误在web.config转换过程中混淆了一切.您可以安全地删除以下节点:
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Run Code Online (Sandbox Code Playgroud)
4)我找不到在nlog/targets节点下只转换单个目标的方法.要更改记录器的连接字符串,我必须使用父节点上的xdt:Transform ="Replace"复制整个xml节点,如下所示:
<nlog
throwExceptions="true"
internalLogLevel="Trace"
internalLogFile="..\..\..\Logs\nlog-app.log"
xdt:Transform="Replace">
<!--(copy and paste all nlog configuration here)-->
</nlog>
Run Code Online (Sandbox Code Playgroud)
pri*_*e_z 21
我已经管理好了,而没有将所有配置都移到web.config或app.config中.(没有任何内容,完全与web/app.config中的nlog相关联).
1)使用本文:将msbuild配置转换应用于任何配置文件 我已经创建了所有转换,这是必要的并添加了转换任务.
2)然后我检查了是否有其他任务,它们做类似的事情.在我的情况下,有一个由SlowCheetah创建(VS扩展自动添加转换).我把它删除了 - 一切都变好了.(SlowCheetah可以在下一次构建时恢复其设置,因此最好将其删除或禁止其转换任务)
3)我的转换文件看起来像这样:
<?xml version="1.0"?>
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<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">
<targets>
<target xsi:type="Database" name="DbLogging"
connectionString=".\SQLEXPRESS;Initial Catalog=xxxxx;User ID=xxxx;Pwd=xxxx;" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)">
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="DbLogging" />
<logger name="Namespace.*" minlevel="Debug" writeTo="DbLogging" xdt:Transform="SetAttributes(writeTo)" xdt:Locator="Match(name)" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
tbc*_*ord 11
看来我在这方面已经很晚了,但我发现NLog.config文件必须具备以下内容:
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
...
...
</nlog>
Run Code Online (Sandbox Code Playgroud)
NLogTransform.config文件(或其可能具有的任何名称)具有以下内容:
<?xml version="1.0"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
...
...
</nlog>
Run Code Online (Sandbox Code Playgroud)
以下是一些测试NLog转换的示例代码:
var tmpConfigFile = new FileInfo("C:\\NLogs\\NLog.config");
var transformFile = new FileInfo("C:\\Transforms\\NLogTransform.config");
if (transformFile.Exists) {
var xmlTransformableDocument = new XmlTransformableDocument();
xmlTransformableDocument.Load(tmpConfigFile.FullName);
var xmlTransformation = new XmlTransformation(transformFile.FullName);
xmlTransformation.Apply(xmlTransformableDocument);
xmlTransformableDocument.Save(tmpConfigFile.FullName);
}
Run Code Online (Sandbox Code Playgroud)
我通过在转换配置中包含在 web.config 中为 nlog 部分定义的 xmlns:xsi 命名空间来实现此目的。
<nlog xmlns:xsi="...">
<variable name="..." value="..." xdt:Transform="Replace" xdt:Locator="Match(name)" />
</nlog>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12169 次 |
| 最近记录: |