NLog 过滤器将错误更改为警告

NLog filter to change Error to Warning

我目前有以下过滤器

<logger name="*" minLevel="Info" writeTo="dbLog">
  <filters>
    <when condition="contains('${message}', 'failed AntiXss')" action="Ignore" />
    <when condition="contains('${message}', 'Cannot create duplicate candidate')" action="Ignore" />
  </filters>
</logger>

但是我需要将错误记录为警告,而不是忽略错误。这可能吗?

谢谢

不幸的是没有programming/tricks。

级别是通过日志调用设置的,不应由目标更改。

在这些情况下,一个技巧是复制目标并写成 "warning"。

例如

<target name="file"      xsi:type="File" layout="${level}|${message}"/>
<target name="file-warn" xsi:type="File" layout="WARN|{message}"/>