Type : Bug
NLog version: 4.5.0-rc07
Platform: .NET Core 2.0
Hi! I created .net core console app. Added NuGet packages NLog
<PackageReference Include="NLog" Version="4.5.0-rc07" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="4.0.0-beta26" />
and config
<nlog autoReload="false" throwExceptions="true" internalLogFile="d:/0_logs/NLog.log" internalLogLevel="Warn" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Targets.ElasticSearch" />
</extensions>
<variable name="logDirectory" value="${basedir}/logs/${shortdate}" />
<variable name="typeVariable" value="" />
<targets>
<target name="BufferingWrapper" xsi:type="BufferingWrapper" bufferSize="1">
<target name="FallbackFromElasticToFile" xsi:type="FallbackGroup" returnToFirstOnSuccess="true">
<target name="ElasticSearch" xsi:type="ElasticSearch" uri="http://host:9200/" index="logs-${shortdate}" documentType="${typeVariable}" includeAllProperties="true" disableAutomaticProxyDetection="true" layout="${message}">
<field name="host" layout="${machinename}" layoutType="System.String" />
<field name="environment" layout="${env}" layoutType="System.String" />
<field name="processid" layout="${processid}" layoutType="System.Int32" />
<field name="threadid" layout="${threadid}" layoutType="System.Int32" />
<field name="logger" layout="${logger}" layoutType="System.String" />
</target>
<target name="File" xsi:type="File" fileName="${logDirectory}\${logger}.${machinename}.log" createDirs="true" keepFileOpen="false" encoding="utf-8" layout="${longdate} | [${level:uppercase=true}] ${message} ${all-event-properties} ${onexception:inner=${newline}${exception:format=ToString,StackTrace}${newline}}">
</target>
</target>
</target>
</targets>
<rules>
<logger name="*" writeTo="BufferingWrapper" minlevel="Trace" />
</rules>
</nlog>
Application should write log every seconds, but it not work.
I changed config and my app started working. I just deleted FallbackGroup.
Worked config:
xml
<nlog autoReload="false" throwExceptions="true" internalLogFile="d:/0_logs/NLog.log" internalLogLevel="Warn" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Targets.ElasticSearch" />
</extensions>
<variable name="logDirectory" value="${basedir}/logs/${shortdate}" />
<variable name="typeVariable" value="" />
<targets>
<target name="BufferingWrapper" xsi:type="BufferingWrapper" bufferSize="1">
<target name="ElasticSearch" xsi:type="ElasticSearch" uri="http://cg-esd.kad.local:9200/" index="logs-datalake-${shortdate}" documentType="${typeVariable}" includeAllProperties="true" disableAutomaticProxyDetection="true" layout="${message}">
<field name="host" layout="${machinename}" layoutType="System.String" />
<field name="environment" layout="${env}" layoutType="System.String" />
<field name="processid" layout="${processid}" layoutType="System.Int32" />
<field name="threadid" layout="${threadid}" layoutType="System.Int32" />
<field name="logger" layout="${logger}" layoutType="System.String" />
</target>
</target>
</targets>
<rules>
<logger name="*" writeTo="BufferingWrapper" minlevel="Trace" />
</rules>
</nlog>
Why FallbackGroup not work in .net core 2.0? It is my mistake or bug in NLog?
You are probably been affected by the following bug: https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/issues/53 (You should add comment that you are also affected).
Maybe a workaround could be this:
<target name="FallbackFromElasticToFile" xsi:type="FallbackGroup" returnToFirstOnSuccess="true">
<target name="ElasticSearchAsync" xsi:type="AsyncWrapper" timeToSleepBetweenBatches="0" overflowAction="Block" batchSize="10">
<target name="ElasticSearch" xsi:type="ElasticSearch" uri="http://host:9200/" index="logs-${shortdate}" documentType="${typeVariable}" includeAllProperties="true" disableAutomaticProxyDetection="true" layout="${message}">
<field name="host" layout="${machinename}" layoutType="System.String" />
<field name="environment" layout="${env}" layoutType="System.String" />
<field name="processid" layout="${processid}" layoutType="System.Int32" />
<field name="threadid" layout="${threadid}" layoutType="System.Int32" />
<field name="logger" layout="${logger}" layoutType="System.String" />
</target>
</target>
<target name="File" xsi:type="File" fileName="${logDirectory}\${logger}.${machinename}.log" createDirs="true" keepFileOpen="false" encoding="utf-8" layout="${longdate} | [${level:uppercase=true}] ${message} ${all-event-properties} ${onexception:inner=${newline}${exception:format=ToString,StackTrace}${newline}}">
</target>
</target>
Remember to update the logging rule to use FallbackFromElasticToFile (instead of BufferingWrapper)
Thank you! Workaround worked for me. Maybe my app really been affected that bug.
I assume your question has been answered, if not, please let us know!
Most helpful comment
You are probably been affected by the following bug: https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/issues/53 (You should add comment that you are also affected).
Maybe a workaround could be this:
Remember to update the logging rule to use
FallbackFromElasticToFile(instead ofBufferingWrapper)