Robot Logs directly to ElasticSearch NLog target

With some help from UiPath I figured it out. Thanks @Robert_Waldinger !

First of to see where NLog is having issues one can add a Debug Flag to help identify the issue

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogLevel="Debug" internalLogFile="C:\tmp\NLOG_DEBUG.log">
image

This way I could see the the ElasticSearch assembly could not be loaded

After some trial and error I figured out that Elasticsearch.Net.dll, Nest.dll and Log.Targets.ElasticSearch.dll are missing from C:\Program Files\UiPath\Studio\net461

I downloaded the assembly using the Nuget CLI NuGet Gallery | Downloads

.\nuget.exe install NLog.Targets.ElasticSearch -Version 7.7.0 -DirectDownload -Framework net461 -Verbosity normal -Source https://api.nuget.org/v3/index.json -OutputDirectory .\download_folder -NonInteractive

fetched the three .dll from their respective folders. For example:

and copied them to C:\Program Files\UiPath\Studio\net461

Now the target was working and through the debug errors I could find out that I was using the wrong format for the APIKey.

When producing a Key in ElasticCloud one gets the Keys in this format.

<?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">
  <extensions>
    <add assembly="NLog.Targets.ElasticSearch"/>
  </extensions>
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} --##-- {level} --##-- ${message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />
	<target xsi:type="ElasticSearch" name="robotElastic" uri="https://xxxxx.cloud.es.io" 
		cloudId="xxxxxxx"
		apiKeyId="xxxxx"
		apiKey="xxxxxx"
		index="robot-${date:format=yyyy.MM}"
		documentType=""
		includeDefaultFields="true"
		includeAllProperties="true"
		layout="${message}"
		requireAuth="false"
		
	/>
  </targets>
  <rules>
    <logger name="WorkflowLogging" minlevel="Info" writeTo="robotElastic,WorkflowLogFiles" final="true" />
  </rules>

</nlog>

And It finally works :slight_smile:

2 Likes