I have follow xml file
<?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"
autoReload="true"
internalLogLevel="Debug"
internalLogFile="c:\work\log-internal.txt">
<!-- Load the necessary NLog extensions -->
<extensions>
<add assembly="Elastic.NLog.Targets" />
<add assembly="Elastic.CommonSchema.NLog" />
</extensions>
<targets>
<!-- Define the Elasticsearch target -->
<target xsi:type="ElasticSearch"
name="elastic"
nodeUris=""
username="elastic"
password="">
<!-- Define the index format -->
<indexFormat>testing</indexFormat>
<!-- Define a custom JsonLayout to include only specific fields -->
<layout xsi:type="EcsLayout" IncludeEventProperties="true"
excludeProperties="url.domain,url.path">
</layout>
</target>
</targets>
<rules>
<!-- Define logging rules -->
<!-- This rule logs only 'Error' level logs from the specified logger to Elasticsearch -->
<logger name="ElasticsearchLoging.Controllers.HomeController"
minLevel="Error"
maxLevel="Error"
writeTo="elastic" />
</rules>
</nlog>
I am using the lastest elastic library "Elastic.NLog.Targets" and "Elastic.CommonSchema.NLog" for saving the logs on elasticsearch and it is working fine
output:
{
"@timestamp": "2020-02-20T16:07:06.7109766+11:00",
"log.level": "Info",
"message": "Info "X" 2.2",
"ecs.version": "8.6.0",
"log": {
"logger": "Elastic.CommonSchema.NLog.Tests.LogTestsBase"
},
"labels": {
"ValueX": "X"
},
"agent": {
"type": "Elastic.CommonSchema.NLog",
"version": "1.6.0"
},
"event": {
"created": "2020-02-20T16:07:06.7109766+11:00",
"severity": 6,
"timezone": "Romance Standard Time"
},
"host": {
"ip": [ "127.0.0.1" ],
"name": "LOCALHOST"
},
"process": {
"executable": "C:\Program Files\dotnet\dotnet.exe",
"name": "dotnet",
"pid": 17592,
"thread.id": 17592,
"title": "15.0.0.0"
},
"server": { "user": { "name": "MyUser" } },
"service": {
"name": "Elastic.CommonSchema",
"type": "dotnet",
"version": "1.6.0"
},
"metadata": {
"SomeY": 2.2
},
"MessageTemplate": "Info {ValueX} {SomeY} {NotX}"
}
this is how the logs are getting store in elasticsearch. But i want to store specific fields on elastisearch like this
{
"@timestamp": "2020-02-20T16:07:06.7109766+11:00",
"log.level": "Info",
"message": "Info "X" 2.2",
"ecs.version": "8.6.0",
}
if anyone know about how can i control the structure with those above libraries kindly share here.