Skip to content

Commit

Permalink
Remove WriteEvent usages (#453)
Browse files Browse the repository at this point in the history
- Ensure correct embdedded logical name for UParser.regexes.cs
- Remove WriteEvent usages
  • Loading branch information
Mpdreamz authored Oct 3, 2024
1 parent a79063e commit 4ba40a1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ private IBufferedChannel<LogEvent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public EcsDataStreamChannel(DataStreamChannelOptions<TEcsDocument> options) : th
public EcsDataStreamChannel(
DataStreamChannelOptions<TEcsDocument> options,
ICollection<IChannelCallbacks<TEcsDocument, BulkResponse>>? 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) { }

/// <summary>
/// Bootstrap the target data stream. Will register the appropriate index and component templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public class EcsIndexChannel<TEcsDocument> : IndexChannel<TEcsDocument>
where TEcsDocument : EcsDocument
{
/// <inheritdoc cref="EcsIndexChannel{TEcsDocument}"/>
public EcsIndexChannel(IndexChannelOptions<TEcsDocument> options) : base(options) =>
options.WriteEvent = async (stream, ctx, @event) =>
await JsonSerializer.SerializeAsync(stream, @event, typeof(TEcsDocument), EcsJsonConfiguration.SerializerOptions, ctx)
.ConfigureAwait(false);
public EcsIndexChannel(IndexChannelOptions<TEcsDocument> options) : base(options) { }

/// <summary>
/// Bootstrap the target index. Will register the appropriate index and component templates
Expand Down
10 changes: 4 additions & 6 deletions src/Elastic.NLog.Targets/ElasticsearchTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ElasticsearchTarget : TargetWithLayout

/// <summary>
/// Gets or sets the format string for the Elastic search index. The current <c>DateTimeOffset</c> is passed as parameter 0.
///
///
/// <para> Example: "dotnet-{0:yyyy.MM.dd}"</para>
/// <para> If no {0} parameter is defined the index name is effectively fixed</para>
/// </summary>
Expand Down Expand Up @@ -213,8 +213,7 @@ private EcsDataStreamChannel<NLogEcsDocument> CreateDataStreamChannel(Distribute
var dataStreamNamespace = DataStreamNamespace?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
var channelOptions = new DataStreamChannelOptions<NLogEcsDocument>(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<NLogEcsDocument>(channelOptions, new[] { new InternalLoggerCallbackListener<NLogEcsDocument>() });
Expand All @@ -228,9 +227,8 @@ private EcsIndexChannel<NLogEcsDocument> 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)
Expand All @@ -251,7 +249,7 @@ protected override void CloseTarget()

/// <inheritdoc />
protected override void Write(LogEventInfo logEvent)
{
{
var ecsDoc = _layout.RenderEcsDocument(logEvent);
_channel?.TryWrite(ecsDoc);
}
Expand Down

0 comments on commit 4ba40a1

Please sign in to comment.