/// <summary> /// Implement this method to execute your behavior processing. /// </summary> /// <param name="input">Inputs to the current call to the target.</param> /// <param name="getNext">Delegate to execute to get the next delegate in the behavior chain.</param> /// <returns> /// Return value from the target. /// </returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { string name = Thread.CurrentPrincipal.Identity.Name; if (string.IsNullOrEmpty(name)) { name = "unknown User"; } string param = input.Arguments.Cast <object>().Aggregate("", (current, parameter) => current + (", " + parameter)); if (param.Length > 0) { param = param.Substring(2); } Logger.Logger.Write(string.Format("{0}: Enter Method: {1}.{2}({3})", name, input.MethodBase.DeclaringType, input.MethodBase.Name, param), TraceEventType); IMethodReturn value = getNext()(input, getNext); value.InvokeAfterCall(input, d => { if (d.Exception != null) { Logger.Logger.Write(d.Exception); } Logger.Logger.Write(string.Format("{0}: Exit Method: {1}.{2}({3})", name, input.MethodBase.DeclaringType, input.MethodBase.Name, param), TraceEventType); }); return(value); }
/// <summary> /// Implement this method to execute your handler processing. /// </summary> /// <param name="input">Inputs to the current call to the target.</param> /// <param name="getNext">Delegate to execute to get the next delegate in the handler /// chain.</param> /// <returns> /// Return value from the target. /// </returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { string name = "unknown User"; try { string n = Thread.CurrentPrincipal.Identity.Name; if (string.IsNullOrEmpty(n)) { name = null; } } catch (ObjectDisposedException) { //kann passieren, dann steht weiter unknown user im log } string param = input.Arguments.Cast <object>() .Aggregate("", (current, parameter) => current + (", " + (parameter == null ? "null" : parameter.ToString()))); if (param.Length > 0) { param = param.Substring(2); } Logger.Logger.Write(string.Format("{0}: Enter Method: {1}.{2}({3})", name, input.MethodBase.DeclaringType, input.MethodBase.Name, param), TraceEventType.Verbose); IMethodReturn value = getNext()(input, getNext); value.InvokeAfterCall(input, d => { if (d.Exception != null) { Logger.Logger.Write(d.Exception); } Logger.Logger.Write(string.Format("{0}: Exit Method: {1}.{2}({3})", name, input.MethodBase.DeclaringType, input.MethodBase.Name, param), TraceEventType.Verbose); }); return(value); }