Skip to content

Commit

Permalink
Added factory method for EcsTextFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrapavy committed Oct 25, 2023
1 parent 0b170d0 commit 6aa416e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpContextAccessor>()));

public static IHostBuilder UseSerilogEvents(this IHostBuilder builder, Action<HostBuilderContext, LoggerConfiguration>? configureLogger = null, bool logEcsEvents = true, bool logToConsole = true)
{
Expand All @@ -30,7 +32,7 @@ public static IHostBuilder UseSerilogEvents(this IHostBuilder builder, Action<Ho
configuration.WriteTo.Async(c => {
if (logEcsEvents)
{
c.Console(new EcsTextFormatter(new EcsTextFormatterConfiguration().MapCustom(EcsMapper.MapLogEvent).MapExceptions(true).MapCurrentThread(true).MapHttpContext(context.Configuration.Get<HttpContextAccessor>())));
c.Console(CreateEcsTextFormatter(context));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/SerilogEcsLogging/SerilogEcsLogging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>mrapavy</Authors>
<PackageProjectUrl>https://github.com/mrapavy/serilog-ecs-logging</PackageProjectUrl>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 6aa416e

Please sign in to comment.