【发布时间】:2017-04-07 08:14:53
【问题描述】:
我使用 NLog 作为日志框架,并尝试找出哪些设置对于外部 transformation 配置文件(例如 NLog.Debug.config)是“最佳”的。
在wiki page of the project 上,有两种选择:
- 内联(例如在 Web.config 或 App.config 内)
- 以
<nlog>作为 根元素 的外部配置文件中的简化 xml
这是一个示例配置:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true">
<targets async="true">
<target name="Warn" xdt:Transform="Remove" xdt:Locator="Match(name)" />
</targets>
<rules>
<logger writeTo="Warn" xdt:Transform="Remove" xdt:Locator="Match(writeTo)" />
</rules>
</nlog>
尽管有许多命名空间,Visual Studio 2015 仍显示以下警告:
The 'nlog' element is not declared.
当我将 nlog 部分放在 <configuration> 元素中时,此警告会消失,但会出现很多“消息”,表明名称、目标、异步等元素是未知的:
Could not find schema information for the element 'target'.
如果我从命名空间定义 (xmlns:nlog="...) 中删除后缀 nlog,则根元素会被接受,但我会看到诸如 target、xdt:Transform、xdt:Locator 等元素的警告上:
The element 'http://www.nlog-project.org/schemas/NLog.xsd:target' is abstract or its type is abstract.
The 'autoreload' attribute is not declared.
The 'name' attribute is not declared.
...
我已经尝试将命名空间移动到不同的元素或为每个元素或属性赋予相应的前缀,但没有任何帮助让所有警告或消息消失...
编辑:属性仍然标有警告,例如:
The 'http://schemas.microsoft.com/XML-Document-Transform:Locator' attribute is not declared.
【问题讨论】:
标签: xml namespaces configuration-files nlog xdt-transform