Cannot save to ElasticSearch via NLog

I have a password protected ElasticSearch instance. When i try to use NLog.Targets.ElasticSearch in my .net core 3.1 application to directly save logs to Elastic search. I am getting error.
my Log .config file is as follows.:-1:
'

<?xml version="1.0" encoding="utf-8" ?>





<!-- write to file  -->
<target xsi:type="File" name="alldata" fileName="demo-${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />

<!-- another file log. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="otherFile-web" fileName="demo-Other-${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
'

and i am getting the following error:-
'2020-05-15 15:30:14.6834 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll
2020-05-15 15:30:14.6999 Info Loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll
2020-05-15 15:30:14.7151 Info NLog.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 1.6.2.1321. Product version: 1.6.2.
2020-05-15 15:30:14.7151 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll succeeded!
2020-05-15 15:30:14.7151 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Targets.ElasticSearch.dll
2020-05-15 15:30:14.7279 Info Loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Targets.ElasticSearch.dll
2020-05-15 15:30:14.7530 Info NLog.Targets.ElasticSearch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3eb62cd298662c6a. File version: 1.0.0.0. Product version: 1.0.0+d8acd793e03f16712546aa28266328852039efe8.
2020-05-15 15:30:14.7627 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Targets.ElasticSearch.dll succeeded!
2020-05-15 15:30:14.7627 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Web.AspNetCore.dll
2020-05-15 15:30:14.7627 Info Loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Web.AspNetCore.dll
2020-05-15 15:30:14.7627 Info NLog.Web.AspNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.9.2.1619. Product version: 4.9.2.
2020-05-15 15:30:14.7766 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NLog.Web.AspNetCore.dll succeeded!
2020-05-15 15:30:14.7766 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.dll
2020-05-15 15:30:14.7766 Info Loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.dll
2020-05-15 15:30:14.7766 Info NlogDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. File version: 1.0.0.0. Product version: 1.0.0.
2020-05-15 15:30:14.8075 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.dll succeeded!
2020-05-15 15:30:14.8075 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.Views.dll
2020-05-15 15:30:14.8075 Info Loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.Views.dll
2020-05-15 15:30:14.8075 Info NlogDemo.Views, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. File version: 1.0.0.0. Product version: 1.0.0.
2020-05-15 15:30:14.8317 Info Auto loading assembly file: D:\ELK\MyProjects\Nlogdemosln\NlogDemo\bin\Debug\netcoreapp3.1\NlogDemo.Views.dll succeeded!
2020-05-15 15:30:14.8317 Info Message Template Auto Format enabled
2020-05-15 15:30:14.8379 Info Loading assembly: NLog.Web.AspNetCore
2020-05-15 15:30:14.8379 Info Loading assembly: NLog.Targets.ElasticSearch
2020-05-15 15:30:14.9081 Info Adding target BufferingTargetWrapper(Name=ElasticSearch)
2020-05-15 15:30:14.9342 Info Adding target FileTarget(Name=alldata)
2020-05-15 15:30:14.9342 Info Adding target FileTarget(Name=otherFile-web)
2020-05-15 15:30:15.0114 Info Found 62 configuration items
2020-05-15 15:30:15.1537 Info Configuration initialized.
2020-05-15 15:30:15.1537 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.0.11381. Product version: 4.7.0+4d138800820311d0b60b6437f1dd2ed1d571d47d.
2020-05-15 15:31:16.0577 Error ElasticSearch: Failed to send log messages. status= Exception: System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Http.HttpConnection.FillAsync()
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)'

Nlog,config file is as follows:-

<?xml version="1.0" encoding="utf-8" ?>





<!-- write to file  -->
<target xsi:type="File" name="alldata" fileName="demo-${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />

<!-- another file log. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="otherFile-web" fileName="demo-Other-${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

for some reaosn the NLOG.COnfig file is not getting pasted in the question. So u can find it at https://stackoverflow.com/questions/61817166/cannot-save-to-elasticsearch-via-nlog

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.