【问题标题】:NLog Syslog configuration filesNLog 系统日志配置文件
【发布时间】:2019-03-22 19:14:57
【问题描述】:

我正在尝试在 asp.net core 2.2 项目中设置系统日志,但我找不到任何可以解释这一点的东西。 NLog.Target.Syslog 上的示例代码对新手来说解释不够。我已经使用示例代码设置日志记录到文件。

<target xsi:type="Syslog" name="cee-udp">
      <sl:layout xsi:type="SimpleLayout" text="@cee: {&quot;message&quot;: &quot;${message}&quot;}" />
      <sl:messageCreation>
        <sl:facility>Local4</sl:facility>
        <sl:rfc>Rfc5424</sl:rfc>
        <sl:rfc5424>
          <sl:hostname xsi:type="SimpleLayout" text="${machinename}" />
          <sl:appName xsi:type="SimpleLayout" text="DAEMON.MyAppName" />
          <sl:procId xsi:type="SimpleLayout" text="${processid}" />
          <sl:msgId xsi:type="SimpleLayout" text="${threadid}" />
          <sl:disableBom>true</sl:disableBom>
        </sl:rfc5424>
      </sl:messageCreation>
    </target>

您能否解释一下我应该为 machinename 输入什么 - 是目标主机还是源主机?如何指定 syslog 服务器的 IP?什么是 process 和 threadID,它从哪里获取变量?

我在另一台机器上运行 Virtual Syslog Server 来测试它。

【问题讨论】:

标签: configuration nlog syslog


【解决方案1】:

只需将此配置目标添加到项目的 Nlog.config 文件中的部分:

<target xsi:type="Syslog" name="syslogTarget">
  <sl:layout xsi:type="SimpleLayout" text="${message}" />
  <sl:messageSend>
    <sl:udp server="127.0.0.1" port="514" connectionCheckTimeout="0" />
  </sl:messageSend>
</target>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 2014-04-22
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多