Code Monkey home page Code Monkey logo

Comments (3)

tveyes-user avatar tveyes-user commented on May 26, 2024 1

I ended up doing this:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:sl="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd" throwExceptions="true">
  <targets>
    <target xsi:type="ColoredConsole" name="console">
      <layout xsi:type="SimpleLayout" text="${message}${exception:format=ToString,StackTrace}" />
    </target>
    <target xsi:type="sl:Syslog" name="syslog">
      <sl:layout xsi:type="SimpleLayout" text="${message}${exception:format=ToString,StackTrace}" />
      <sl:enforcement>
        <sl:splitOnNewLine>false</sl:splitOnNewLine>
        <sl:transliterate>false</sl:transliterate>
        <sl:replaceInvalidCharacters>false</sl:replaceInvalidCharacters>
        <sl:truncateFieldsToMaxLength>true</sl:truncateFieldsToMaxLength>
        <sl:truncateMessageTo>1024</sl:truncateMessageTo>
      </sl:enforcement>
      <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="${processname}" />
          <sl:procId xsi:type="SimpleLayout" text="${processid}" />
          <sl:msgId xsi:type="SimpleLayout" text="${threadid}" />
          <sl:structuredData>
            <sl:fromEventProperties xsi:type="SimpleLayout" text="[app@0 ${all-event-properties:format=[key]=&quot;[value]&quot;:separator= :includeCallerInformation=False}]" />
          </sl:structuredData>
        </sl:rfc5424>
      </sl:messageCreation>
      <sl:messageSend>
        <sl:protocol>UDP</sl:protocol>        
        <sl:udp>
          <sl:server>syslogserver</sl:server>
          <sl:port>514</sl:port>
        </sl:udp>
      </sl:messageSend>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="console" />
    <logger name="*" minlevel="Debug" writeTo="syslog" />
  </rules>
</nlog>

It seems a little bit hacky because I'm building the structured data string from scratch in the layout, but it does work. I think it would probably break if any of my properties included a quote (") or brackets.

Thanks!

-Z

from nlog.targets.syslog.

zorlack avatar zorlack commented on May 26, 2024

I think I misunderstood how this is supposed to work. I'm closing this out.

from nlog.targets.syslog.

luigiberrettini avatar luigiberrettini commented on May 26, 2024

Take a look at:

  1. https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer
  2. https://github.com/graffen/NLog.Targets.Syslog/blob/3ae37f0c21170617f8c2071536f54a6d5d84d47b/src/TestApp/NLog.config#L59
  3. https://github.com/graffen/NLog.Targets.Syslog/blob/54c28889aaebbdf1ca7ce3689b55034dd80a8217/src/NLog.Targets.Syslog/MessageCreation/StructuredData.cs#L27

from nlog.targets.syslog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.