定义日志范畴对象
Inheritance: IDisposable
Esempio n. 1
0
        /// <summary>
        /// 进入一个日志范畴
        /// </summary>
        /// <param name="scope">要进入的日志范畴</param>
        /// <returns></returns>
        public static LogScope EnterScope(LogScope scope)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            if (scope.Parent != null)
            {
                throw new InvalidOperationException("无法进入这个范畴,因为这个范畴已经被使用");
            }

            scope.Parent = CurrentScope;
            return(CurrentScope = scope);
        }
Esempio n. 2
0
        /// <summary>
        /// 离开指定的范畴,若指定范畴在当前上下文不存在,则不进行任何操作,并返回 null 。
        /// </summary>
        /// <param name="scope">要离开的范畴</param>
        /// <returns></returns>
        public static LogScope LeaveScope(LogScope scope)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var current = CurrentScope;

            while (current != scope)
            {
                current._leaved = true;
                current         = current.Parent;

                if (current == null)
                {
                    return(null);
                }
            }

            return(CurrentScope = current.Parent);
        }
Esempio n. 3
0
        /// <summary>
        /// 离开指定的范畴,若指定范畴在当前上下文不存在,则不进行任何操作,并返回 null 。
        /// </summary>
        /// <param name="scope">要离开的范畴</param>
        /// <returns></returns>
        public static LogScope LeaveScope( LogScope scope )
        {
            if ( scope == null )
            throw new ArgumentNullException( "scope" );

              var current = CurrentScope;

              while ( current != scope )
              {
            current._leaved = true;
            current = current.Parent;

            if ( current == null )
              return null;
              }

              return CurrentScope = current.Parent;
        }
Esempio n. 4
0
        /// <summary>
        /// 进入一个日志范畴
        /// </summary>
        /// <param name="scope">要进入的日志范畴</param>
        /// <returns></returns>
        public static LogScope EnterScope( LogScope scope )
        {
            if ( scope == null )
            throw new ArgumentNullException( "scope" );

              if ( scope.Parent != null )
            throw new InvalidOperationException( "无法进入这个范畴,因为这个范畴已经被使用" );

              scope.Parent = CurrentScope;
              return CurrentScope = scope;
        }