diff --git a/src/SerilogEcsLogging/Logging/EcsEvent.cs b/src/SerilogEcsLogging/Logging/EcsEvent.cs index 569a5cf..12b3188 100644 --- a/src/SerilogEcsLogging/Logging/EcsEvent.cs +++ b/src/SerilogEcsLogging/Logging/EcsEvent.cs @@ -6,7 +6,7 @@ public class EcsEvent : IEcsEvent public string EventKind { get; } - public IList? Tags { get; } + public IList Tags { get; } public bool? EventOutcome { get; set; } @@ -24,7 +24,7 @@ public EcsEvent(string eventAction, string eventKind = Elastic.CommonSchema.Even { EventAction = eventAction; EventKind = eventKind; - Tags = tags; + Tags = tags ?? new List(); EventOutcome = eventOutcome; EventDuration = eventDuration; EventMessage = message; diff --git a/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs b/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs index 0ce6923..5059358 100644 --- a/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs +++ b/src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs @@ -8,6 +8,8 @@ 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 static IHostBuilder UseSerilogEvents(this IHostBuilder builder, Action? configureLogger = null, bool logEcsEvents = true, bool logToConsole = true) { return builder.UseSerilog((context, configuration) => { @@ -28,12 +30,11 @@ 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(new EcsTextFormatter(new EcsTextFormatterConfiguration().MapCustom(EcsMapper.MapLogEvent).MapExceptions(true).MapCurrentThread(true).MapHttpContext(context.Configuration.Get()))); } else { - c.Console(outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}][{Level:u3}][{SourceContext}][{ThreadId}]{Scope} {Message}{NewLine}{Exception}"); + c.Console(outputTemplate: TraceTemplate); } }); }