Example #1
0
        public IDisposable BeginScope <TState>(TState state)
        {
            var scope = new IMLoggerScope(_name, state);

            scope.Context = IMLoggerScope.Current?.Context ?? GetNewActivityContext();
            return(IMLoggerScope.Push(scope, _store));
        }
Example #2
0
        public static IDisposable Push(IMLoggerScope scope, IMLoggerStore store)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }

            var temp = Current;

            Current        = scope;
            Current.Parent = temp;

            Current.Node = new IMLoggerScopeNode()
            {
                StartTime = DateTimeOffset.UtcNow,
                State     = Current._state,
                Name      = Current._name
            };

            if (Current.Parent != null)
            {
                Current.Node.Parent = Current.Parent.Node;
                Current.Parent.Node.Children.Add(Current.Node);
            }
            else
            {
                Current.Context.Root = Current.Node;
                store.AddActivity(Current.Context);
            }

            return(new DisposableAction(() =>
            {
                Current.Node.EndTime = DateTimeOffset.UtcNow;
                Current = Current.Parent;
            }));
        }