コード例 #1
0
        public static IDisposable Push(object state)
        {
            IDictionary <string, object> stateValues;

            if (state is IEnumerable <KeyValuePair <string, object> > stateEnum)
            {
                // Convert this to a dictionary as we have scenarios where we cannot have duplicates. In this
                // case, if there are dupes, the later entry wins.
                stateValues = new Dictionary <string, object>();
                foreach (var entry in stateEnum)
                {
                    stateValues[entry.Key] = entry.Value;
                }
            }
            else
            {
                // There's nothing we can do with other states.
                return(null);
            }

            Current = new DictionaryLoggerScope(new ReadOnlyDictionary <string, object>(stateValues), Current);
            return(new DisposableScope());
        }
コード例 #2
0
 private DictionaryLoggerScope(IReadOnlyDictionary <string, object> state, DictionaryLoggerScope parent)
 {
     State  = state;
     Parent = parent;
 }