Serilog.Events.LogEvent.AddPropertyIfAbsent C# (CSharp) Method

AddPropertyIfAbsent() public method

Add a property to the event if not already present.
public AddPropertyIfAbsent ( LogEventProperty property ) : void
property LogEventProperty The property to add.
return void
        public void AddPropertyIfAbsent(LogEventProperty property)
        {
            if (property == null) throw new ArgumentNullException(nameof(property));
            if (!_properties.ContainsKey(property.Name))
                _properties.Add(property.Name, property.Value);
        }

Usage Example

Exemplo n.º 1
0
        public void Enrich(Serilog.Events.LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var traceId       = StringUtil.DecodeBase64ToUTF8(_httpContextAccessor.HttpContext.Request.Headers[Constants.TraceIdHeader].ToString());
            var userSessionId = StringUtil.DecodeBase64ToUTF8(_httpContextAccessor.HttpContext.Request.Headers[Constants.UserSessionIdHeader].ToString());

            logEvent.AddPropertyIfAbsent(new LogEventProperty("TraceId", new ScalarValue(traceId)));
            logEvent.AddPropertyIfAbsent(new LogEventProperty("UserSessionId", new ScalarValue(userSessionId)));
        }
All Usage Examples Of Serilog.Events.LogEvent::AddPropertyIfAbsent