public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { SerilogScope scope = this; while (scope != null) { var properties = scope._state as IEnumerable <KeyValuePair <string, object> >; if (properties != null) { foreach (var kv in properties) { if (kv.Key == SerilogLoggerAdapter.OriginalFormatPropertyName) { continue; } var key = kv.Key; var destructureObject = false; if (key.StartsWith("@")) { key = key.Substring(1); destructureObject = true; } var property = propertyFactory.CreateProperty(key, kv.Value, destructureObject); logEvent.AddPropertyIfAbsent(property); } } scope = scope._parent; } logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Scope", _scopesChain)); }
public SerilogScope(SerilogScope parent, object state) { _parent = parent; _state = state; var scope = GetScopeValue(state); _scopesChain = parent?._scopesChain ?? new LinkedList <object>(); _scopesChain.AddLast(scope); }
public IDisposable BeginScope <TState>(TState state) { return(SerilogScope.Push(state)); }
public static IDisposable Push(object state) { Current = new SerilogScope(Current, state); return(new DisposableScope()); }