public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args) { unitOfWork = ServiceLocator.Current.GetInstance <IUnitOfWork>(); unitOfWork.BeginTransaction(); base.OnEntry(args); }
public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args) { Debug.WriteLine(string.Format("[{0}] took {1}ms to execute", new StackTrace().GetFrame(1).GetMethod().Name, _StopWatch.ElapsedMilliseconds)); base.OnExit(args); }
public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args) { _methodCallIdentifier = Guid.NewGuid(); _StopWatch = Stopwatch.StartNew(); using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("Guid: " + _methodCallIdentifier + Environment.NewLine + "Timer started on method: " + args.Method.Name + Environment.NewLine + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); writer.WriteLine("-----------------------------------------------------------------------------" + Environment.NewLine); } base.OnEntry(args); }
public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args) { _methodCallIdentifier = Guid.NewGuid(); Debug.WriteLine(string.Format("[{0}] took {1}ms to execute", new StackTrace().GetFrame(1).GetMethod().Name, _StopWatch.ElapsedMilliseconds)); using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("Guid: " + _methodCallIdentifier + Environment.NewLine + "Timer execute on method :" + args.Method.Name + Environment.NewLine + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString() + " " + "Time: " + string.Format("[{0}] took {1}ms to execute", new StackTrace().GetFrame(1).GetMethod().Name, _StopWatch.ElapsedMilliseconds)); writer.WriteLine("-----------------------------------------------------------------------------" + Environment.NewLine); } base.OnExit(args); }
public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args) { try { _StopWatch = new Stopwatch(); _StopWatch.Start(); string className = "", arguments = ""; if (args.Method != null) { if (args.Method.DeclaringType != null) { className = args.Method.DeclaringType.Namespace + args.Method.DeclaringType.Name; } } StringBuilder parameterValues = new StringBuilder(); for (int i = 0; i < args.Arguments.Count; i++) { if (parameterValues.Length > 0) { parameterValues.Append(", "); } parameterValues.AppendFormat( "{0} = {1}", parameterNames[i], args.Arguments[i].ToJSON() ?? "null"); } _StopWatch = Stopwatch.StartNew(); var log = new LogMessage(); log.Message = parameterValues.ToString(); log.Level = EnumLogLevel.Info.ToString(); log.Module = args.Method.DeclaringType.Name + "/" + GetMethodName(args.Method); DomainEvents._Container.Resolve <IEventBus>().Publish(log, "LogMessage"); } catch (Exception e) { throw e; } base.OnEntry(args); }
public override void OnException(PostSharp.Aspects.MethodExecutionArgs args) { log4net.ILog log = _logger; if (log == null) { log = InternalFieldFinder.Instance.GetInstance <log4net.ILog>(args.Method, args.Instance); } if (log == null) { log = FallBackLogger; } log.Error(Msg, args.Exception); args.FlowBehavior = _suppressException ? FlowBehavior.Continue : FlowBehavior.RethrowException; if (TraceParameters && args.Arguments != null && args.Arguments.Count > 0) { var sb = new StringBuilder(); for (int i = 0; i < args.Arguments.Count; i++) { object arg = args.Arguments[i]; sb.Append(i).Append(". - "); if (arg == null) { sb.AppendLine("<NULL>"); } else { sb.AppendLine(arg.ToString()); } } log.Error(sb.ToString()); } if (WrapExceptionType != null) { args.Exception = (Exception)Activator.CreateInstance(WrapExceptionType, Msg, args.Exception); args.FlowBehavior = FlowBehavior.ThrowException; } log = null; }
public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args) { _StopWatch = Stopwatch.StartNew(); base.OnEntry(args); }
public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args) { unitOfWork.Dispose(); base.OnExit(args); }