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

RemovePropertyIfPresent() public method

Remove a property from the event, if present. Otherwise no action is performed.
public RemovePropertyIfPresent ( string propertyName ) : void
propertyName string The name of the property to remove.
return void
        public void RemovePropertyIfPresent(string propertyName)
        {
            _properties.Remove(propertyName);
        }

Usage Example

        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory factory)
        {
            var trace = new StackTrace();
            const int index = 5;
            if (trace.FrameCount < index)
            {
                logEvent.RemovePropertyIfPresent("ClassName");
                logEvent.RemovePropertyIfPresent("MethodName");
                return;
            }

            var method = trace.GetFrame(index).GetMethod();

            logEvent.AddOrUpdateProperty(factory.CreateProperty("ClassName", method.ReflectedType));
            logEvent.AddOrUpdateProperty(factory.CreateProperty("MethodName", method.ToString()));
        }
All Usage Examples Of Serilog.Events.LogEvent::RemovePropertyIfPresent