无法通过NLog保存到ElasticSearch

时间:2020-05-15 10:34:07

标签: elasticsearch .net-core nlog

我有一个受密码保护的ElasticSearch实例。当我尝试在.net core 3.1应用程序中使用NLog.Targets.ElasticSearch直接将日志保存到Elastic搜索时。我出错了。文本日志文件已成功创建。但是条目不会进入弹性搜索。 我的Log .config文件如下:-1:

<?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="info"
      internalLogFile="internalLog.txt">
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
    <add assembly="NLog.Targets.ElasticSearch"/>
  </extensions>

  <!-- the targets to write to -->
  <targets>
    <target name="ElasticSearch" xsi:type="BufferingWrapper" flushTimeout="1">
      <target xsi:type="ElasticSearch"
         requireAuth="true"
         username="Rahul"
         password="Test@123"
         uri="http://192.168.52.85:9200"
         index="webapidemo"     />
    </target>

    <!-- 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}" />
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--<logger name="*" minlevel="Info" writeTo="alldata" />-->
    <logger name="*" minlevel="Warning" writeTo="alldata" />
    <!--<logger name="*" minlevel="Info" writeTo="alldata" />-->
    <!--Skip non-critical Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" maxLevel="Info" final="true" />
    <!-- BlackHole without writeTo -->
    <logger name="*" minlevel="Trace" writeTo="otherFile-web" />
    <logger name="*" minlevel="Debug" writeTo="ElasticSearch" />
  </rules>
</nlog>

我收到以下错误:-

'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)

0 个答案:

没有答案
相关问题