Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public SerilogScope(SerilogScope parent, object state)
        {
            _parent = parent;
            _state  = state;
            var scope = GetScopeValue(state);

            _scopesChain = parent?._scopesChain ?? new LinkedList <object>();
            _scopesChain.AddLast(scope);
        }
Ejemplo n.º 3
0
 public IDisposable BeginScope <TState>(TState state)
 {
     return(SerilogScope.Push(state));
 }
Ejemplo n.º 4
0
 public static IDisposable Push(object state)
 {
     Current = new SerilogScope(Current, state);
     return(new DisposableScope());
 }