2

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

项目的 wiki 页面上,有两个选项:

  1. 内联(例如在 Web.config 或 App.config 内)
  2. 外部配置文件中的简化 xml<nlog>作为根元素

这是一个示例配置:

<?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'.

如果我从命名空间定义 ( )中删除后缀nlogxmlns: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.

4

1 回答 1

0

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

该文件包含在 NLog.Schema 包中(链接到 Nuget

编辑xmlns:这对我有用,NLog 在哪里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">
于 2016-11-23T23:18:15.137 回答