Serilog 两次写入日志

mok*_*mok 6 serilog asp.net-core-2.0 kibana-6

我使用SerilogElasticsearch sink 的配置如下:

Log.Logger = new LoggerConfiguration()
                    .MinimumLevel.Verbose()
                    .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose)
                    .Enrich.FromLogContext()
                    .Enrich.WithExceptionDetails()
                    .Enrich.WithProperty("Application", "abc")
                    .Enrich.WithProperty("Environment", env.EnvironmentName)
                    .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(Configuration["LoggingEndpoint"]))
                    {
                        AutoRegisterTemplate = true,
                        CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true) // Better formatting for exceptions
                    })
Run Code Online (Sandbox Code Playgroud)

// 然后:

services.AddLogging(loggingBuilder =>
            loggingBuilder.AddSerilog());
Run Code Online (Sandbox Code Playgroud)

但是我可以在 Kibana 上看到每个日志两次,时间戳相差几毫秒。我尝试了此处提供的解决方案,以防万一它们可能有所帮助,但没有运气。

Jor*_*ijk 14

情况可能是这样,因为您正在 appsettings.json 以及内部代码中配置 Serilog。这会将所有内容记录两次。