【问题标题】:External NLog.config without Visual Studio warnings or messages at the Error List window错误列表窗口中没有 Visual Studio 警告或消息的外部 NLog.config
【发布时间】:2017-04-07 08:14:53
【问题描述】:

我使用 NLog 作为日志框架,并尝试找出哪些设置对于外部 transformation 配置文件(例如 NLog.Debug.config)是“最佳”的。

wiki page of the project 上,有两种选择:

  1. 内联(例如在 Web.config 或 App.config 内)
  2. <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 部分放在 &lt;configuration&gt; 元素中时,此警告会消失,但会出现很多“消息”,表明名称、目标、异步等元素是未知的: 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


    【解决方案1】:

    最好的方法是下载 NLog.XSD 并将其添加到同一目录中。

    该文件包含在 NLog.Schema 包中 (link to Nuget)

    编辑:这对我有用,其中 NLog 是 xmlns 而不是 xmlns:nlog

    <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">
    

    【讨论】:

    • 对不起,我已经把文件复制到同一个目录了。此外,在XML - Schemas 下的 VS 中,架构被标记为正在使用。这没有帮助:-(
    • 更新了xmlns。为我工作
    • 更新了 xmlns,将最新的 NLog.Schema nuget 包 (4.3.11) 安装到我的项目中(我的 NLog.xsd 被新的替换了) - 对“目标”和属性等节点的警告像 'name', 'xdt:Transform', 'xdt:Locator' 仍然存在... :-( The element 'http://www.nlog-project.org/schemas/NLog.xsd:target' is abstract or its type is abstract.
      The 'name' attribute is not declared.
    • 对不起,不适合我。请看我上面的答案。
    猜你喜欢
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    相关资源
    最近更新 更多