/// <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); }
/// <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); }
/// <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; }
/// <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; }