5

When I run the sample program.cs (https://github.com/serilog/serilog-sinks-elasticsearch/blob/dev/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs)

I get this error. Please advise :-)

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.Http.WinHttpRequestCallback.RequestCallback(IntPtr handle, WinHttpRequestState state, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at System.Net.Http.WinHttpRequestCallback.WinHttpCallback(IntPtr handle, IntPtr context, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at Interop.WinHttp.WinHttpCloseHandle(IntPtr handle)
   at Interop.WinHttp.SafeWinHttpHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalDispose()
   at System.Net.Http.WinHttpRequestState.ClearSendRequestState()
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
2019-10-03T10:38:57.2468492Z Failed to create the template. Elasticsearch.Net.ElasticsearchClientException: An error occurred while sending the request.. Call: Status code unknown from: HEAD /_template/serilog-events-template ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The parameter is incorrect
   at System.Net.Http.WinHttpException.ThrowExceptionUsingLastError()
   at System.Net.Http.WinHttpHandler.InternalSendRequestAsync(WinHttpRequestState state)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.Transport`1.HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response)
   at Elasticsearch.Net.Transport`1.FinalizeResponse[TResponse](RequestData requestData, IRequestPipeline pipeline, List`1 seenExceptions, TResponse response)
   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
   at Elasticsearch.Net.Specification.IndicesApi.LowLevelIndicesNamespace.TemplateExistsForAll[TResponse](String name, IndexTemplateExistsRequestParameters requestParameters)
   at Serilog.Sinks.Elasticsearch.ElasticsearchSinkState.RegisterTemplateIfNeeded() in C:\Users\john\Source\Repos\serilog-sinks-elasticsearch\src\Serilog.Sinks.Elasticsearch\Sinks\ElasticSearch\ElasticsearchSinkState.cs:line 161
[12:38:57 INF] Hello, world!
[12:38:57 DBG] Dividing 10 by 0
[12:38:57 ERR] Something went wrong
System.DivideByZeroException: Attempted to divide by zero.
   at Serilog.Sinks.Elasticsearch.Sample.Program.Main(String[] args) in C:\Users\john\Source\Repos\serilog-sinks-elasticsearch\sample\Serilog.Sinks.Elasticsearch.Sample\Program.cs:line 60
[12:38:57 DBG] Reusing string by True
Press any key to continue . . .
1
  • That first exn is from the SelfLog, and it's on closing - I wonder is that server accessible etc? Normally SelfLog messages go ignored, and sinks failing to forward to servers just buffer until their buffers are exhausted and life moves on. If this is 100% reproducible and logs are flowing to the server normally, then I'd say logging an issue on that sink might make sense? Commented Oct 4, 2019 at 7:15

1 Answer 1

4

Error turned out to be not setting the AutoRegisterTemplateVersion to something like

AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.