elasticsearch 调整ElasticsearchSinkOptions.NumberOfShards在SeriLog中不在.Net core中工作
在按SeriLog写入日志时,为ElasticSearch设置NumberOfShard时出现问题。 我在.NETCore中这样配置Serilogelasticsearch 调整ElasticsearchSinkOptions.NumberOfShards在SeriLog中不在.Net core中工作,elasticsearch,.net-core,kibana,elastic-stack,serilog,elasticsearch,.net Core,Kibana,Elastic Stack,Serilog,在按SeriLog写入日志时,为ElasticSearch设置NumberOfShard时出现问题。 我在.NETCore中这样配置Serilog .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.ElasticConnectionUrl)) { AutoRegisterTemplate = true,
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.ElasticConnectionUrl))
{
AutoRegisterTemplate = true,
IndexFormat = config.ElasticIndex + "-{0:yyyy.MM.dd}",
NumberOfShards = 2,
NumberOfReplicas = 0
}));
但是当我查询Kibana中创建的索引的设置时,numberOfShards仍然是5(默认值)。即使对于NumberOfReplicates也不会影响
我正在使用ELK stack跟踪日志
有人知道为什么吗?您可以在代码或appSettings.json配置中进行Serilog配置。如果您正在这样做:
var loggerConfiguration = new LoggerConfiguration()
.ReadFrom.Configuration(configuration) // <= this reads from config
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.ElasticConnectionUrl))
{
AutoRegisterTemplate = true,
IndexFormat = config.ElasticIndex + "-{0:yyyy.MM.dd}",
NumberOfShards = 2,
NumberOfReplicas = 0
})); // this gets partially ignored
如果JSON文件中的索引格式为空,那么可能会有一个名为“log stash-{0:YYYY-MM-DD}”的索引,但也会有您在代码中添加的索引。URI也是如此。如果在JSON接收器WriteTo
和代码中的ElasticsearchSinkOptions
中添加了一个,那么可能会有两个
配置为JSON或代码。选择一个(很遗憾)。有关更多信息,请参见:
我一直在寻找一种在代码中使用默认配置的方法,这种配置可能会被配置文件覆盖,因为我正试图为我们公司的各种API创建一个通用的、自以为是的IHostBuilder,但是Serilog的表现很好。我的解决方案是将Sinks配置移出Serilog config部分,单独定义它,然后自己加载(使用相同的格式-字符串名称,Args Dictionary),然后在代码中手动创建配置。您可以在代码中或在appSettings.json配置中进行Serilog配置。如果您正在这样做:
var loggerConfiguration = new LoggerConfiguration()
.ReadFrom.Configuration(configuration) // <= this reads from config
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.ElasticConnectionUrl))
{
AutoRegisterTemplate = true,
IndexFormat = config.ElasticIndex + "-{0:yyyy.MM.dd}",
NumberOfShards = 2,
NumberOfReplicas = 0
})); // this gets partially ignored
如果JSON文件中的索引格式为空,那么可能会有一个名为“log stash-{0:YYYY-MM-DD}”的索引,但也会有您在代码中添加的索引。URI也是如此。如果在JSON接收器WriteTo
和代码中的ElasticsearchSinkOptions
中添加了一个,那么可能会有两个
配置为JSON或代码。选择一个(很遗憾)。有关更多信息,请参见:
我一直在寻找一种在代码中使用默认配置的方法,这种配置可能会被配置文件覆盖,因为我正试图为我们公司的各种API创建一个通用的、自以为是的IHostBuilder,但是Serilog的表现很好。我的解决方案是将Sinks配置移出Serilog config部分,并单独定义它,然后自己加载(使用相同的格式-string Name,Args Dictionary),然后在代码中手动创建配置