I am trying to start logging in ElasticSearch but no logs are found in the server and if I enable the diagnostics mode an exception is raised:
That's how my Startup.cs looks:
//ElasticSearch Logs
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://myserver.com:9243/"))
{
ModifyConnectionSettings = x => x.BasicAuthentication("elastic", "mypassword"),
AutoRegisterTemplate = true,
})
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
The following is my Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseSerilog();
});
This is what I have inside a controller:
_logger.LogError(new Exception("test"), "An error has occurred.");
_logger.LogInformation("The {User} has just executed {Action}.", "username", "actionName");
Log.Error("this is my first log");
The exception I am getting:
2021-08-19T21:09:15.2793348Z Failed to create the template. Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: PUT /_template/serilog-events-template. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [default : {dynamic_templates=[{numerics_in_fields={match_pattern=regex, path_match=fields.[\d+]$, mapping={norms=false, index=true, type=text}}}, {string_fields={mapping={norms=false, index=true, type=text, fields={raw={ignore_above=256, index=true, type=keyword}}}, match_mapping_type=string, match=}}], properties={message={index=true, type=text}, exceptions={type=nested, properties={ExceptionMessage={type=object, properties={MemberType={type=integer}}}, StackTraceString={index=true, type=text}, HResult={type=integer}, RemoteStackTraceString={index=true, type=text}, RemoteStackIndex={type=integer}, Depth={type=integer}}}}}]" CausedBy: "Type: mapper_parsing_exception Reason: "Root mapping definition has unsupported parameters: [default : {dynamic_templates=[{numerics_in_fields={match_pattern=regex, path_match=fields.[\d+]$, mapping={norms=false, index=true, type=text}}}, {string_fields={mapping={norms=false, index=true, type=text, fields={raw={ignore_above=256, index=true, type=keyword}}}, match_mapping_type=string, match=}}], properties={message={index=true, type=text}, exceptions={type=nested, properties={ExceptionMessage={type=object, properties={MemberType={type=integer}}}, StackTraceString={index=true, type=text}, HResult={type=integer}, RemoteStackTraceString={index=true, type=text}, RemoteStackIndex={type=integer}, Depth={type=integer}}}}}]""
at Elasticsearch.Net.Transport1.HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response) at Elasticsearch.Net.Transport1.FinalizeResponse[TResponse](RequestData requestData, IRequestPipeline pipeline, List1 seenExceptions, TResponse response) at Elasticsearch.Net.Transport1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Elasticsearch.Net.NamespacedClientProxy.DoRequest[TResponse](HttpMethod post, String url, PostData body, IRequestParameters params)
at Elasticsearch.Net.Specification.IndicesApi.LowLevelIndicesNamespace.PutTemplateForAll[TResponse](String name, PostData body, PutIndexTemplateRequestParameters requestParameters)
at Serilog.Sinks.Elasticsearch.ElasticsearchSinkState.RegisterTemplateIfNeeded()
Any clue what I may be missing or any tip about how to find out where the error is?