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

AddOrUpdateProperty() public method

Add a property to the event if not already present, otherwise, update its value.
public AddOrUpdateProperty ( LogEventProperty property ) : void
property LogEventProperty The property to add or update.
return void
        public void AddOrUpdateProperty(LogEventProperty property)
        {
            if (property == null) throw new ArgumentNullException(nameof(property));
            _properties[property.Name] = property.Value;
        }

Usage Example

Exemplo n.º 1
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            const string prefix = "NimbusMessage.";

            var message = DispatchLoggingContext.NimbusMessage;
            if (message == null) return;

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty($"{prefix}MessageType", message.Payload?.GetType().FullName));
            foreach (var property in typeof (NimbusMessage).GetProperties())
            {
                if (property.Name == nameof(NimbusMessage.Payload)) continue;

                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty($"{prefix}{property.Name}", property.GetValue(message)));
            }
        }
All Usage Examples Of Serilog.Events.LogEvent::AddOrUpdateProperty