Skip to content
Rolf Kristensen edited this page Nov 13, 2020 · 48 revisions

Configuration Syntax

<targets>
  <target xsi:type="ElasticSearch" 
          name="String"
          uri="Layout"
          cloudId="Layout"
          index="Layout"
          documentType="Layout"
          includeAllProperties="Boolean"
          excludedProperties="String"
          disableAutomaticProxyDetection="Boolean"
          requireAuth="Boolean"
          username="Layout"
          password="Layout">
    <field name="String" layout="Layout" layoutType="Type" /><!-- repeated, optional -->
  </target>
</targets>

Parameters

  • name - Name of the target. String
  • uri - Uri of a Elasticsearch node. Multiple can be passed comma separated. Ignored if cloud id is provided. Layout Default: http://localhost:9200
  • cloudId - Id of an elastic cloud hosted deployment. Layout Default: empty
  • index - Index to write to, if it doesn't exist it will be created. Layout Default: logstash-${date:format=yyyy.MM.dd}
  • documentType - Type of document. Layout Default: _doc

    Version 7.2 (and older) used the default logevent but it has now been deprecated.

  • opCodeCreate (since version 7.5.0) - Change OpCode from the default index to create for support of data-streams in Elastic 7.9 Boolean
  • fields - A collection of fields. Each field contains a mapping between a NLog layout and a named field.
    • name - Name of the field. String
    • layout - Layout that should be used to calculate the value for the field. Layout
    • layoutType - .Net type to convert the field into. Type Default: System.String
  • includeAllProperties - Optionally include all properties from the log event. Boolean Default: False
  • excludedProperties - Works with includeAllProperties to exclude specific properties. String
  • maxRecursionLimit - Limits how far the reflection will go down the object graph. Introduce with 7.2.0. Default: -1
    • -1 = No limits without reference loop checking (Default - Can give stackoverflow/deadlock for complex objects)
    • 0 = No reflection only perform object ToString
    • 1 = Simple reflection where only direct properties are included.
    • 2 = Full reflection but with checking of reference loops
  • disableAutomaticProxyDetection (since version 2.0.5) - Optionally disable automatic proxy detection. Boolean
  • disablePing (since version 5.1.0) - Set it to true to disable use of ping to checking if node is alive. Boolean
  • enableHttpCompression (since version 5.1.0) - Set it to true to enable HttpCompression (Must be enabled on server). Boolean
  • disableCertificateValidation (since version 7.2.0) - Set it to true to disable SSL certificate validation. Boolean
  • pipeline (since version 5.1.0) -Optionally configure pipeline. Layout
  • proxyAddress (since version 7.2.0) - Optionally configure proxy address. Layout
  • proxyUserName (since version 7.2.0) - Optionally configure proxy login username. Layout
  • proxyPassword (since version 7.2.0) - Optionally configure proxy login password. Layout
  • requireAuth - Optionally enable basic authentication. Boolean Default: False
  • username - Username for basic authentication. Must be provided when using elastic cloud. Layout
  • password - Password for basic authentication. Must be provided when using elastic cloud. Layout

Including MDLC as Field (NET Core - BeginScope)

<target xsi:type="ElasticSearch">
    <field name="mdlc" layoutType="System.Object">
        <layout xsi:type="JsonLayout" includeMdlc="true" />
    </field>
</target>

Using ConnectionString for ElasticSearch Uri

Example of appsettings.json

{
  "ConnectionStrings": {
    "ElasticUrl": "http://localhost:9200"
  }
}

Can be extracted using ${configsetting} from NLog.Extensions.Logging nuget package:

  • ${configsetting:item=ConnectionStrings.ElasticUrl}

Example of app.config:

<configuration>
  <connectionStrings>
    <add name="ElasticUrl" connectionString="http://localhost:9200"/>
  </connectionStrings>
</configuration>

Can be extracted using ${appsetting} from when using NLog 4.6.5:

  • ${appsetting:item=ConnectionStrings.ElasticUrl}
Clone this wiki locally