Пример #1
0
    private void InternalInterceptSynchronous(IInvocation invocation, OperateLogAttribute attribute)
    {
        var methodInfo = invocation.Method ?? invocation.MethodInvocationTarget;
        var log        = CreateOpsLog(methodInfo.DeclaringType.FullName, methodInfo.Name, attribute.LogName, invocation.Arguments, _userContext);

        try
        {
            invocation.Proceed();
            log.Succeed = "true";
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            WriteOpsLog(log);
        }
    }
Пример #2
0
    private async Task <TResult> InternalInterceptAsynchronous <TResult>(IInvocation invocation, OperateLogAttribute attribute)
    {
        TResult result;

        var methodInfo = invocation.Method ?? invocation.MethodInvocationTarget;
        var log        = CreateOpsLog(methodInfo.DeclaringType.FullName, methodInfo.Name, attribute.LogName, invocation.Arguments, _userContext);

        try
        {
            invocation.Proceed();
            var task = (Task <TResult>)invocation.ReturnValue;
            result      = await task;
            log.Succeed = "true";
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            WriteOpsLog(log);
        }
        return(result);
    }