diff --git a/examples/aspnetcore-with-serilog/appsettings.Development.json b/examples/aspnetcore-with-serilog/appsettings.Development.json index 8983e0fc..3c5c8eab 100644 --- a/examples/aspnetcore-with-serilog/appsettings.Development.json +++ b/examples/aspnetcore-with-serilog/appsettings.Development.json @@ -3,7 +3,8 @@ "LogLevel": { "Default": "Information", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Elastic.Apm": "Error" } } } diff --git a/examples/aspnetcore-with-serilog/appsettings.json b/examples/aspnetcore-with-serilog/appsettings.json index d9d9a9bf..c1cc9590 100644 --- a/examples/aspnetcore-with-serilog/appsettings.json +++ b/examples/aspnetcore-with-serilog/appsettings.json @@ -3,7 +3,8 @@ "LogLevel": { "Default": "Information", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Elastic.Apm": "Error" } }, "AllowedHosts": "*" diff --git a/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs b/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs index c0eba776..cb36716f 100644 --- a/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs +++ b/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs @@ -169,7 +169,6 @@ private IBufferedChannel CreatIngestChannel(ElasticsearchLoggerOptions { IndexFormat = loggerOptions.Index.Format, IndexOffset = loggerOptions.Index.IndexOffset, - WriteEvent = async (stream, ctx, logEvent) => await logEvent.SerializeAsync(stream, ctx).ConfigureAwait(false), TimestampLookup = l => l.Timestamp, }; SetupChannelOptions(_channelConfigurations, indexChannelOptions); diff --git a/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsDataStreamChannel.cs b/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsDataStreamChannel.cs index 04f08750..857def85 100644 --- a/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsDataStreamChannel.cs +++ b/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsDataStreamChannel.cs @@ -26,10 +26,7 @@ public EcsDataStreamChannel(DataStreamChannelOptions options) : th public EcsDataStreamChannel( DataStreamChannelOptions options, ICollection>? callbackListeners - ) : base(options, callbackListeners) => - options.WriteEvent = async (stream, ctx, @event) => - await JsonSerializer.SerializeAsync(stream, @event, typeof(TEcsDocument), EcsJsonConfiguration.SerializerOptions, ctx) - .ConfigureAwait(false); + ) : base(options, callbackListeners) { } /// /// Bootstrap the target data stream. Will register the appropriate index and component templates diff --git a/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsIndexChannel.cs b/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsIndexChannel.cs index d0bc1385..a1784440 100644 --- a/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsIndexChannel.cs +++ b/src/Elastic.Ingest.Elasticsearch.CommonSchema/EcsIndexChannel.cs @@ -18,10 +18,7 @@ public class EcsIndexChannel : IndexChannel where TEcsDocument : EcsDocument { /// - public EcsIndexChannel(IndexChannelOptions options) : base(options) => - options.WriteEvent = async (stream, ctx, @event) => - await JsonSerializer.SerializeAsync(stream, @event, typeof(TEcsDocument), EcsJsonConfiguration.SerializerOptions, ctx) - .ConfigureAwait(false); + public EcsIndexChannel(IndexChannelOptions options) : base(options) { } /// /// Bootstrap the target index. Will register the appropriate index and component templates diff --git a/src/Elastic.NLog.Targets/ElasticsearchTarget.cs b/src/Elastic.NLog.Targets/ElasticsearchTarget.cs index 81d0a6fb..cc1d0677 100644 --- a/src/Elastic.NLog.Targets/ElasticsearchTarget.cs +++ b/src/Elastic.NLog.Targets/ElasticsearchTarget.cs @@ -55,7 +55,7 @@ public class ElasticsearchTarget : TargetWithLayout /// /// Gets or sets the format string for the Elastic search index. The current DateTimeOffset is passed as parameter 0. - /// + /// /// Example: "dotnet-{0:yyyy.MM.dd}" /// If no {0} parameter is defined the index name is effectively fixed /// @@ -213,8 +213,7 @@ private EcsDataStreamChannel CreateDataStreamChannel(Distribute var dataStreamNamespace = DataStreamNamespace?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty; var channelOptions = new DataStreamChannelOptions(transport) { - DataStream = new DataStreamName(dataStreamType, dataStreamSet, dataStreamNamespace), - WriteEvent = async (stream, ctx, logEvent) => await logEvent.SerializeAsync(stream, ctx).ConfigureAwait(false), + DataStream = new DataStreamName(dataStreamType, dataStreamSet, dataStreamNamespace) }; SetupChannelOptions(channelOptions); var channel = new EcsDataStreamChannel(channelOptions, new[] { new InternalLoggerCallbackListener() }); @@ -228,9 +227,8 @@ private EcsIndexChannel CreateIndexChannel(DistributedTransport { IndexFormat = indexFormat, IndexOffset = indexOffset, - WriteEvent = async (stream, ctx, logEvent) => await logEvent.SerializeAsync(stream, ctx).ConfigureAwait(false), TimestampLookup = l => l.Timestamp, - OperationMode = indexOperation, + OperationMode = indexOperation }; if (_hasIndexEventId) @@ -251,7 +249,7 @@ protected override void CloseTarget() /// protected override void Write(LogEventInfo logEvent) - { + { var ecsDoc = _layout.RenderEcsDocument(logEvent); _channel?.TryWrite(ecsDoc); } diff --git a/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj b/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj index d507e4b2..4806848b 100644 --- a/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj +++ b/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs b/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs index 274a6653..926b9008 100644 --- a/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs +++ b/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs @@ -38,16 +38,17 @@ public HttpContextEnricher(IHttpContextAccessor httpContextAccessor) => /// Enrich the log event. public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - var r = new HttpContextEnrichments(); - if (Adapter.HasContext) - { - r.Http = Adapter.Http; - r.Server = Adapter.Server; - r.Url = Adapter.Url; - r.UserAgent = Adapter.UserAgent; - r.Client = Adapter.Client; - r.User = Adapter.User; - } + if (!Adapter.HasContext) + return; + + var r = new HttpContextEnrichments { + Http = Adapter.Http, + Server = Adapter.Server, + Url = Adapter.Url, + UserAgent = Adapter.UserAgent, + Client = Adapter.Client, + User = Adapter.User + }; logEvent.AddPropertyIfAbsent(new LogEventProperty(PropertyName, new ScalarValue(r))); }