Skip to content

Commit

Permalink
Expose ITextFormatter to RenderMessage in Serilog (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Sep 23, 2024
1 parent ec6774c commit c68c131
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using Elastic.CommonSchema.Serilog.Adapters;
using Serilog.Events;

Expand Down Expand Up @@ -32,6 +33,11 @@ public interface IEcsTextFormatterConfiguration : IEcsDocumentCreationOptions
/// Stop certain keys to be persisted as <see cref="EcsDocument.Metadata"/> or <see cref="BaseFieldSet.Labels"/>
/// </summary>
ISet<string>? LogEventPropertiesToFilter { get;set; }

/// <summary>
/// Provide a <see cref="IFormatProvider"/> to <see cref="LogEvent.RenderMessage(System.IO.TextWriter,System.IFormatProvider)"/>
/// </summary>
IFormatProvider? MessageFormatProvider { get; set; }
}

/// <summary> Provides configuration options for <see cref="EcsTextFormatter{TEcsDocument}"/> </summary>
Expand Down Expand Up @@ -66,6 +72,9 @@ public class EcsTextFormatterConfiguration<TEcsDocument> : IEcsTextFormatterConf
/// <inheritdoc cref="IEcsTextFormatterConfiguration.LogEventPropertiesToFilter"/>
public ISet<string>? LogEventPropertiesToFilter { get; set; }

/// <inheritdoc cref="IEcsTextFormatterConfiguration.MessageFormatProvider"/>
public IFormatProvider? MessageFormatProvider { get; set; }

/// <inheritdoc cref="IEcsTextFormatterConfiguration{TEcsDocument}.MapCustom"/>
public Func<TEcsDocument, LogEvent, TEcsDocument>? MapCustom { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.CommonSchema.Serilog/LogEventConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static TEcsDocument ConvertToEcs<TEcsDocument>(LogEvent logEvent, IEcsTex
var user = GetUser(logEvent, configuration);
if (user != null) ecsEvent.User = user;

ecsEvent.Message = logEvent.RenderMessage();
ecsEvent.Message = logEvent.RenderMessage(configuration.MessageFormatProvider);
ecsEvent.Log = GetLog(logEvent);
ecsEvent.Agent = GetAgent(logEvent) ?? DefaultAgent;
ecsEvent.Event = GetEvent(logEvent);
Expand Down

0 comments on commit c68c131

Please sign in to comment.