Skip to content

Commit

Permalink
Tags initialized to empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
mrapavy committed Oct 24, 2023
1 parent 48c85b2 commit 93631ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/SerilogEcsLogging/Logging/EcsEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class EcsEvent : IEcsEvent

public string EventKind { get; }

public IList<string>? Tags { get; }
public IList<string> Tags { get; }

public bool? EventOutcome { get; set; }

Expand All @@ -24,7 +24,7 @@ public EcsEvent(string eventAction, string eventKind = Elastic.CommonSchema.Even
{
EventAction = eventAction;
EventKind = eventKind;
Tags = tags;
Tags = tags ?? new List<string>();
EventOutcome = eventOutcome;
EventDuration = eventDuration;
EventMessage = message;
Expand Down
7 changes: 4 additions & 3 deletions src/SerilogEcsLogging/Logging/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostBuilderContext, LoggerConfiguration>? configureLogger = null, bool logEcsEvents = true, bool logToConsole = true)
{
return builder.UseSerilog((context, configuration) => {
Expand All @@ -28,12 +30,11 @@ 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(new EcsTextFormatter(new EcsTextFormatterConfiguration().MapCustom(EcsMapper.MapLogEvent).MapExceptions(true).MapCurrentThread(true).MapHttpContext(context.Configuration.Get<HttpContextAccessor>())));
}
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);
}
});
}
Expand Down

0 comments on commit 93631ae

Please sign in to comment.