[英]Serilog doesn't write logs into AWS Elasticsearch Service
I am using Serilog to write logs into AWS Elasticsearch Service in my .NET Core application but when logging into Kibana I don't see any logs written.我正在使用 Serilog 将日志写入我的 .NET Core 应用程序中的AWS Elasticsearch Service ,但是在登录 Kibana 时我没有看到任何写入的日志。
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
{
const string esUrl = "https://aws-es-thinger.us-west-1.es.amazonaws.com";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(esUrl))
{
ModifyConnectionSettings = conn =>
{
var httpConnection = new AwsHttpConnection("us-east-1");
var pool = new SingleNodeConnectionPool(new Uri(esUrl));
var conf = new ConnectionConfiguration(pool, httpConnection);
return conf;
},
AutoRegisterTemplate = true
}).CreateLogger();
}
I am able to use HttpClient
to get response successfully.我能够使用HttpClient
成功获得响应。
Also, I am able to load the Kibana and ElasticSearch urls from my browser.此外,我还可以从浏览器加载 Kibana 和 ElasticSearch 网址。 Please help me with what am I missing here.请帮我解决我在这里缺少的东西。
EDIT Getting below error when connecting in Startup:编辑在启动时连接时出现以下错误:
System.Net.Http.WinHttpException: A connection with the server could not be established System.Net.Http.WinHttpException:无法建立与服务器的连接
I needed to provide AWS Access Key and Secret Key in Connection Settings to get it work as below:我需要在连接设置中提供 AWS 访问密钥和秘密密钥才能使其工作如下:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(awsSettings.ElasticSearchUrl))
{
ModifyConnectionSettings = conn =>
{
var httpConnection = new AwsHttpConnection(awsSettings.Region
, new StaticCredentialsProvider(new AwsCredentials
{
AccessKey = awsSettings.AccessKey,
SecretKey = awsSettings.SecretKey,
}));
var pool = new SingleNodeConnectionPool(new Uri(awsSettings.ElasticSearchUrl));
var conf = new ConnectionConfiguration(pool, httpConnection);
return conf;
},
ConnectionTimeout = new TimeSpan(0, 10, 0),
IndexFormat = "xxxxx-{0:yyyy.MM}",
FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
EmitEventFailureHandling.WriteToFailureSink |
EmitEventFailureHandling.RaiseCallback,
FailureSink = new LoggerConfiguration().WriteTo
.RollingFile(new JsonFormatter(), "XXXXX-{Date}.txt").CreateLogger()
})
.CreateLogger();
Hope, it helps somebody in future.希望,它可以帮助将来的某个人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.