gpt4 book ai didi

c# - 简单的Serilog + ElasticSearch

转载 作者:行者123 更新时间:2023-12-02 23:15:06 28 4
gpt4 key购买 nike

ElasticSearch看,该程序没有向Kibana发布任何内容。我想念什么吗?

using System;

using Serilog;
using Serilog.Sinks.Elasticsearch;


namespace DemoService
{
class Program
{
static void Main(string[] args)
{
var loggerConfig = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://ipaddress:9200"))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6
});


Log.Information("The time is {Now}", DateTime.Now);
}
}
}

最佳答案

我得到了它的工作。

       var log = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://ipaddress"))
{
AutoRegisterTemplate = true,
//AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
EmitEventFailureHandling.WriteToFailureSink |
EmitEventFailureHandling.RaiseCallback,
FailureSink = new FileSink("./failures.txt", new JsonFormatter(),
null)
}
).CreateLogger();

log.Information(new ApplicationException("This is working!").ToString());

关于c# - 简单的Serilog + ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56310066/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com