/// <summary> /// 拦截方法 /// </summary> /// <param name="context">方法元数据</param> public void Advise(MethodAdviceContext context) { this._runningLog.BuildRuningInfo(context); this._runningLog.BuildBasicInfo(context); this._runningLog.BuildMethodArgsInfo(context); context.Proceed(); this._runningLog.BuildReturnValueInfo(context); //无需事务 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { //持久化 LogMediator.Write(this._runningLog); scope.Complete(); } }
/// <summary> /// 发生异常事件 /// </summary> /// <param name="context">方法元数据</param> /// <param name="exception">异常实例</param> protected virtual void OnException(MethodAdviceContext context, Exception exception) { if (!context.TargetMethod.IsDefined(typeof(SkipExceptionAttribute), true)) { //初始化异常日志 this._exceptionLog.BuildBasicInfo(context); this._exceptionLog.BuildMethodArgsInfo(context); this._exceptionLog.BuildExceptionInfo(exception); //无需事务 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { //插入数据库 Guid newId = LogMediator.Write(this._exceptionLog); scope.Complete(); //初始化异常消息 this._exceptionMessage = new ExceptionMessage(exception.Message, newId); } } }