elasticsearch 使用serilog和ILogger记录到弹性搜索,elasticsearch,azure-functions,kibana,serilog,iloggerfactory,elasticsearch,Azure Functions,Kibana,Serilog,Iloggerfactory" /> elasticsearch 使用serilog和ILogger记录到弹性搜索,elasticsearch,azure-functions,kibana,serilog,iloggerfactory,elasticsearch,Azure Functions,Kibana,Serilog,Iloggerfactory" />

elasticsearch 使用serilog和ILogger记录到弹性搜索

elasticsearch 使用serilog和ILogger记录到弹性搜索,elasticsearch,azure-functions,kibana,serilog,iloggerfactory,elasticsearch,Azure Functions,Kibana,Serilog,Iloggerfactory,我已经编写了一个函数来返回一个ILogger实例。这样,我可以在所有代码中获得一致的日志记录 我的问题是,当从不同类型的运行时/程序调用时,日志记录有时会在某些运行时失败!也就是说,如果我在WebAPI中使用日志记录,一切都很好,但是如果我在Azure函数V1中使用它,它永远不会工作 记录器不会抛出或以其他方式指示任何错误。我唯一的失败迹象是Kibana/ElasticSearch中没有显示任何内容 如何调试/排除使用serilog接收器制作的Ilogger实例以进行ElasticSearch?

我已经编写了一个函数来返回一个ILogger实例。这样,我可以在所有代码中获得一致的日志记录

我的问题是,当从不同类型的运行时/程序调用时,日志记录有时会在某些运行时失败!也就是说,如果我在WebAPI中使用日志记录,一切都很好,但是如果我在Azure函数V1中使用它,它永远不会工作

记录器不会抛出或以其他方式指示任何错误。我唯一的失败迹象是Kibana/ElasticSearch中没有显示任何内容

如何调试/排除使用serilog接收器制作的Ilogger实例以进行ElasticSearch?

public static Microsoft.Extensions.Logging.ILogger CreateILogger(string loggerName, string elasticPassword, string elasticIndexName = "logs-index-{0:yyyy.MM}")
{
    var elasticNodeURI = "https://1234567890.southeastasia.azure.elastic-cloud.com:9243";
    var elasticTemplateName = "logstemplate";

    var serilogLogger = new LoggerConfiguration()
        .Enrich.FromLogContext()
        .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticNodeURI))
        {
            IndexFormat = elasticIndexName,
            AutoRegisterTemplate = true,
            InlineFields = true,
            TemplateName = elasticTemplateName,
            ModifyConnectionSettings = x => x.BasicAuthentication("LogUser", elasticPassword),
            AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
            MinimumLogEventLevel = Serilog.Events.LogEventLevel.Debug,
            CustomFormatter = new ElasticsearchJsonFormatter()
        });

    var loggerFactory = (ILoggerFactory)new LoggerFactory();
    loggerFactory.AddSerilog(serilogLogger.CreateLogger());

    return loggerFactory.CreateLogger(loggerName);
}