0

我已经为 DotNet Core WebAPI 设置了 EFK。现在,我想从 appsettings.json 文件中获取 EFK 节点信息。但是,我无法理解如何为 appsettings.json 制作 JSON。以下是我的代码:

创建 ElasticSearch 接收器:

var options = new ElasticsearchSinkOptions(elasticsearchLoggerConfiguration.Nodes)
        {
            MinimumLogEventLevel = LevelConvert.ToSerilogLevel(elasticsearchLoggerConfiguration.MinimumLogLevel),
            AutoRegisterTemplate = true,
            AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
            IndexFormat = "test-{0:yyyy.MM.dd}"
        };

ElasticsearchLogger 配置:

public class ElasticsearchLoggerConfiguration
{
    /// <summary>
    /// Gets or sets the Elasticsearch nodes.
    /// </summary>
    /// <value>
    /// The Elasticsearch nodes.
    /// </value>
    public IEnumerable<Uri> Nodes { get; set; }

配置绑定:

var elasticsearchLoggerConfiguration = new ElasticsearchLoggerConfiguration();                    
loggerConfiguration.Bind(elasticsearchLoggerConfiguration);

应用设置.json

{
  "Type": "Elasticsearch",
  "nodes": [
    {
      "Uri": {
        "AbsoluteUri": "http://elastic:changeme@someIP:9200"
      }
} ]

我无法在 appsettings.json 文件中为节点(Uri)创建 JSON。请建议。

4

0 回答 0