Xml 错误列表窗口中没有Visual Studio警告或消息的外部NLog.config

Xml 错误列表窗口中没有Visual Studio警告或消息的外部NLog.config,xml,namespaces,configuration-files,nlog,xdt-transform,Xml,Namespaces,Configuration Files,Nlog,Xdt Transform,我使用NLog作为日志框架,并尝试找出哪些设置对于外部转换配置文件(例如NLog.Debug.config)是“最佳的” 在上,有两个选项: 内联(例如在Web.config或App.config内) 外部配置文件中的简化xml,其根元素为 以下是一个配置示例: <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmln

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

在上,有两个选项:

  • 内联(例如在Web.config或App.config内)
  • 外部配置文件中的简化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>
    
    我已经尝试将名称空间移动到不同的元素,或者为每个元素或属性指定相应的前缀,但是没有任何帮助让所有警告或消息消失

    编辑:属性仍然标记有以下警告:
    http://schemas.microsoft.com/XML-Document-Transform:Locator'属性未声明。

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

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

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

    
    
    对不起,忘了提及我已将文件复制到同一目录。此外,在VS的
    XML-Schemas
    下,模式被标记为正在使用。这没有帮助:-(更新了
    xmlns
    。适用于Me更新的xmlns,在我的项目中安装了最新的NLog.Schema nuget包(4.3.11)(我的NLog.xsd被替换为新包)-对“target”等节点和“name”、“xdt:Transform”、“xdt:Locator”等属性的警告仍然存在…:-(
    element'http://www.nlog-project.org/schemas/NLog.xsd:target'是抽象的或其类型是抽象的。

    未声明'name'属性。
    对不起,我不是。请参见上面我的答案。
    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.
    ...
    
    <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">