From 4ba40a14ee65f19f5fd99dd95f563b13b18e92a7 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 3 Oct 2024 16:47:33 +0200 Subject: [PATCH] Remove WriteEvent usages (#453) - Ensure correct embdedded logical name for UParser.regexes.cs - Remove WriteEvent usages --- .../ElasticsearchLoggerProvider.cs | 1 - .../EcsDataStreamChannel.cs | 5 +---- .../EcsIndexChannel.cs | 5 +---- src/Elastic.NLog.Targets/ElasticsearchTarget.cs | 10 ++++------ 4 files changed, 6 insertions(+), 15 deletions(-) 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); }