NLOG配置 - 如何在化合物中使用布局变量?

发布于 2025-01-30 07:51:36 字数 502 浏览 3 评论 0原文

在我的nlog配置中,我有一个可容纳我的jsonlayout的变量:

<variable name="jsonLayoutv0.1">
    <layout type="JsonLayout">
      <attribute name="time" layout="${longdate}" />

    </layout>
  </variable>

然后,我想将此布局放在稍后在我的nlog配置中的复合layout中,而无需重新编写整个jsonlayout:

<sl:layout xsi:type="CompoundLayout">
    <layout xsi:type="SimpleLayout" text="@cee: " />
    <INSERT HERE/>
</sl:layout>

我该如何使用可用的变量。在复合层中?

In my NLog Config I have a variable to hold my JsonLayout:

<variable name="jsonLayoutv0.1">
    <layout type="JsonLayout">
      <attribute name="time" layout="${longdate}" />

    </layout>
  </variable>

I then want to place this layout inside a compoundLayout later on in my NLog config without having to re-write the whole jsonLayout again:

<sl:layout xsi:type="CompoundLayout">
    <layout xsi:type="SimpleLayout" text="@cee: " />
    <INSERT HERE/>
</sl:layout>

How can I go about re-using the variable inside a CompoundLayout?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霞映澄塘 2025-02-06 07:51:37

NLOG 5.0.1现在可用: https://www.nuget.orget.orget.org/packages/ nlog/5.0.1 您可以做到这一点:

<nlog>
    <variable name='jsonLayoutv0.1'>
        <layout type='JsonLayout'>
          <attribute name='short_date' layout='${shortdate}' />
          <attribute name='message' layout='${message}' />
        </layout>
     </variable>
    <targets>
    <target name='compoundFile' type='File' fileName='log.txt'>
      <layout type='CompoundLayout'>
        <layout type='SimpleLayout' text='|Before| ' />
        <layout type='${jsonLayoutv0.1}' />
        <layout type='SimpleLayout' text=' |After|' />
      </layout>
    </target>
</nlog>

另请参阅: https:// github.com/nlog/nlog/pull/4940

NLog 5.0.1 is now available: https://www.nuget.org/packages/NLog/5.0.1 so you can do this:

<nlog>
    <variable name='jsonLayoutv0.1'>
        <layout type='JsonLayout'>
          <attribute name='short_date' layout='${shortdate}' />
          <attribute name='message' layout='${message}' />
        </layout>
     </variable>
    <targets>
    <target name='compoundFile' type='File' fileName='log.txt'>
      <layout type='CompoundLayout'>
        <layout type='SimpleLayout' text='|Before| ' />
        <layout type='${jsonLayoutv0.1}' />
        <layout type='SimpleLayout' text=' |After|' />
      </layout>
    </target>
</nlog>

See also: https://github.com/NLog/NLog/pull/4940

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文