Search code examples
configurationnlogsyslog

NLog Syslog configuration files


I am trying to setup syslog in an asp.net core 2.2 project, but I can't find anything that explains this. The sample code on NLog.Target.Syslog doesn't explain enough for a newbie. I have setup logging to file using example code.

<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>

Can you please explain what I should be putting for machinename - is that the target host or the source? How do I specify the IP of the syslog server? What is process and threadID and where is it getting the variables from?

I have Virtual Syslog Server running on another machine to test this.


Solution

  • just add this config target to section in Nlog.config file of your project :

    <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>