Amazon OpenSearch的设置Serilog
我正在尝试设置Serilog,以便将日志从ASP.NET Core WebAPI发送到Amazon OpenSearch的本地实例。我在控制台上看到了日志,但是OpenSearch中没有显示任何内容。
已安装的第三方库:
- Serilog.aspnetcore(6.0.0-dev-00265)
- Serilog.enrichers.enrichers.environment(2.2.1-dev-00787)
- Serilog.sink.sinks.sinks.elasticsearch(9.0.0.0.0.0-beta7)通过开发Docker Compose(9.0.0.0-Beta)
运行(没有安全插件):
program.cs
var logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
{
AutoRegisterTemplate = true,
MinimumLogEventLevel = LogEventLevel.Information,
FailureCallback = FailureCallback,
EmitEventFailure = EmitEventFailureHandling.RaiseCallback | EmitEventFailureHandling.ThrowException
})
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);
controller类:
_logger.LogWarning("Example warning");
_logger.LogError("Example error");
failurecallback
是空的。 OpenSearch Console不会显示任何问题。
可能怎么了?
I'm trying to setup Serilog in order to send logs from ASP.NET Core WebAPI to the local instance of Amazon OpenSearch. I See logs on the console, but nothing is displayed in OpenSearch.
Installed 3rd party libraries:
- Serilog.AspNetCore (6.0.0-dev-00265)
- Serilog.Enrichers.Environment (2.2.1-dev-00787)
- Serilog.Sinks.Elasticsearch (9.0.0-beta7)
OpenSearch run via Development Docker Compose (without security plugin):
Program.cs
var logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
{
AutoRegisterTemplate = true,
MinimumLogEventLevel = LogEventLevel.Information,
FailureCallback = FailureCallback,
EmitEventFailure = EmitEventFailureHandling.RaiseCallback | EmitEventFailureHandling.ThrowException
})
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);
Controller class:
_logger.LogWarning("Example warning");
_logger.LogError("Example error");
FailureCallback
is empty. OpenSearch console doesn't show any issue.
What might be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经尝试了您的设置,这里有一些结果(仅使用稳定版本的软件注意):.
docker-compose二手:
program.cs
,很少有帮助解决故障排除
serilog.debugging.selflog.enable(msg => console.writeline(msg));
- 将显示Serilog的实际错误(很可能您会看到SSL)service> servicepointpointManager中的实际错误。 serverCertificateValidationCallback =(源,证书,链,SSLPOLICYERRORS)=> true;
- 现在停止任何SSL问题(您可以稍后修复它们)我捕获的下一件事是由Serilog生成的[_type]字段的问题,并且不被Elastic&GT接受; v8.2,这很可能会因为您的缓冲区保留旧记录而发生。
采用最新的beta版本用于使用typeName =“ _ doc”时,AWS OpenSearch 2.0.1有另一个错误,其中``compatibily.override_main_response_version = true''设置(请参阅此处的详细信息)
https://github.com/opensearch-project/opensearch-project/openseact/openseact/pull/pull/pull/3530 - 基本上,我建议回滚AWS opensearch to V2。
之后,希望它应该起作用:)
I've tried your setup and here are some results (note using only stable versions of software):
Docker-compose used:
Program.cs
There are few things that should help with troubleshooting
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
- will show real error from Serilog (most likely you will see SSL)ServicePointManager.ServerCertificateValidationCallback = (source, certificate, chain, sslPolicyErrors) => true;
- stop any SSL issues for now (you can fix them later)The next thing I catch is issue with [_type] field that is generated by Serilog and is not accepted by Elastic > v8.2, this most likely will happen because your buffer keep old records.
While latest beta version of Serilog adopted to use TypeName="_doc", AWS opensearch 2.0.1 have another bug with "compatibility.override_main_response_version=true" setting (see details here)
https://github.com/opensearch-project/OpenSearch/pull/3530 - basically I would suggest to rollback AWS OpenSearch to v2.
Afterwards it hopefully should work :)
对我来说,问题是我没有为indexformat属性提供值(在
elasticsearchSinkoptions
对象中)。相反,我将其放在端点上,就像您通过REST插入数据时应该做的那样。总而言之,以下代码为我解决了问题:当然,您还需要正确设置OpenSearch,以便它可以自动将策略自动到您的索引等。
The issue for me was that I hadn't provided the value for the IndexFormat Property (in the
ElasticSearchSinkOptions
object). I had instead put this in the endpoint, as you should do if you insert data through REST. All in all, the below code solved the issue for me:Of course, you also need to setup OpenSearch correctly such that it can autoapply policies to your index, etc.