diff --git a/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs b/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs index 5059358..ca390ab 100644 --- a/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs +++ b/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs @@ -8,7 +8,9 @@ namespace SerilogEcsLogging.Logging; public static class HostBuilderExtensions { - public const string TraceTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}][{MachineName}][{Level:u3}][{SourceContext}][{ThreadId}]{Scope} {Message}{NewLine}{Exception}"; + public const string TraceTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}][{MachineName}][{Level:u3}][{SourceContext}][{ThreadId}]{Scope} {Message}{NewLine}{Exception}"; + + public static EcsTextFormatter CreateEcsTextFormatter(HostBuilderContext context) => new EcsTextFormatter(new EcsTextFormatterConfiguration().MapCustom(EcsMapper.MapLogEvent).MapExceptions(true).MapCurrentThread(true).MapHttpContext(context.Configuration.Get())); public static IHostBuilder UseSerilogEvents(this IHostBuilder builder, Action? configureLogger = null, bool logEcsEvents = true, bool logToConsole = true) { @@ -30,7 +32,7 @@ public static IHostBuilder UseSerilogEvents(this IHostBuilder builder, Action { if (logEcsEvents) { - c.Console(new EcsTextFormatter(new EcsTextFormatterConfiguration().MapCustom(EcsMapper.MapLogEvent).MapExceptions(true).MapCurrentThread(true).MapHttpContext(context.Configuration.Get()))); + c.Console(CreateEcsTextFormatter(context)); } else { diff --git a/src/SerilogEcsLogging/SerilogEcsLogging.csproj b/src/SerilogEcsLogging/SerilogEcsLogging.csproj index 2e249d7..9e0017b 100644 --- a/src/SerilogEcsLogging/SerilogEcsLogging.csproj +++ b/src/SerilogEcsLogging/SerilogEcsLogging.csproj @@ -7,7 +7,7 @@ true mrapavy https://github.com/mrapavy/serilog-ecs-logging - 1.0.2 + 1.0.3