Skip to content

Commit

Permalink
NLog EcsLayout added mapping for EventAction from LogEvent-Property E…
Browse files Browse the repository at this point in the history
…ventName
  • Loading branch information
snakefoot committed Apr 10, 2024
1 parent 36733aa commit 17a2160
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Elastic.CommonSchema.NLog/EcsLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public EcsLayout()
ServerUser = "${environment-user}"; // NLog 4.6.4

EventCode = "${event-properties:EventId}";
EventAction = "${event-properties:EventName}";
_defaultAgent = EcsDocument.CreateAgent(typeof(EcsLayout));

// These values are set by the Elastic.Apm.NLog package
Expand Down Expand Up @@ -165,19 +166,19 @@ private static bool NLogWeb4Registered() =>
/// <summary></summary>
public Layout LogOriginCallSiteLine { get; set; }

/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Action"/>
public Layout EventAction { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Category"/>
public Layout EventCategory { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Id"/>
public Layout EventId { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Code"/>
public Layout EventCode { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Kind"/>
public Layout EventKind { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Severity"/>
public Layout EventSeverity { get; set; }
/// <summary></summary>
/// <inheritdoc cref="EventFieldSet.Duration"/>
public Layout EventDurationMs { get; set; }

/// <summary></summary>
Expand Down Expand Up @@ -511,15 +512,17 @@ private Event GetEvent(LogEventInfo logEventInfo)
var eventCode = EventCode?.Render(logEventInfo);
if (string.IsNullOrEmpty(eventCode) || eventCode == "0")
eventCode = null;
var eventAction = EventAction?.Render(logEventInfo);
var eventKind = EventKind?.Render(logEventInfo);

var evnt = new Event
{
Created = logEventInfo.TimeStamp,
Category = !string.IsNullOrEmpty(eventCategory) ? new[] { eventCategory } : null,
Action = EventAction?.Render(logEventInfo),
Action = !string.IsNullOrEmpty(eventAction) ? eventAction : null,
Id = EventId?.Render(logEventInfo),
Code = eventCode,
Kind = EventKind?.Render(logEventInfo),
Kind = !string.IsNullOrEmpty(eventKind) ? eventKind : null,
Severity = !string.IsNullOrEmpty(eventSeverity)
? long.Parse(eventSeverity)
: GetSysLogSeverity(logEventInfo.Level),
Expand Down

0 comments on commit 17a2160

Please sign in to comment.