Using NLog with Elasticsearch target to forward logs to AWS Elasticsearch as a Service cluster for visualisations in Kibana.
This works fine but I am concerned about using this in production due to ES cluster availability and the impact a cluster failover has, when the logs are sent using the elasticsearch-net client via HTTP.
I am considering using a different target for NLog that sends the logs to a more reliable destination (File, S3 ?) and then having something else (Logstash, AWS Lambda) pick them up and sending them to ES, this way minimising risks on the application itself.
Would like to hear your thoughts
UPDATE
Main concern is app availability and to prevent missing logs secondary target is used.
Using latest NLog and throwExceptions is set to false and not using async targets at this point but considering this as we have a lot of async code.
To give a bit more context the "app" is a set of APIs (WebAPI and WCF) which get 10 - 15K RPM.
Scenario
Request comes in and ES cluster is unavailable.
Case 1 - NLog without async target
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off"
internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target name="elastic"
xsi:type="BufferingWrapper"
flushTimeout="5000">
<target xsi:type="ElasticSearch"
layout="${logger} | ${threadid} | ${message}"
index="logstash-${date:format=yyyy.MM.dd}"
includeAllProperties="true"
uri="...">
<field name="user"
layout="${windows-identity:userName=True:domain=False}"/>
<field name="host"
layout="${machinename}"/>
<field name="number"
layout="1"
layoutType="System.Int32"/>
</target>
</target>
</targets>
<rules>
<logger name="*"
minlevel="Debug"
writeTo="elastic" />
</rules>
</nlog>
Q:
- what happens with the main thread when target can't be reached?
Case 2 - NLog with async target
Using async wrapper for elasticsearch target with queueLimit="10000" batchSize="100"
Q:
- is another thread[B] created ?
- will subsequent requests reuse thread [B] and queue the logging requests?
- what happens when the queueLimit is reached?
- will additional threads [B1 ... Bn] be started? (this will flood connection pool)