Skip to content

Instantly share code, notes, and snippets.

@yaplex
Created June 19, 2017 20:59
Show Gist options
  • Select an option

  • Save yaplex/0a2ce9c34278f80a3f0cb56152b42ec0 to your computer and use it in GitHub Desktop.

Select an option

Save yaplex/0a2ce9c34278f80a3f0cb56152b42ec0 to your computer and use it in GitHub Desktop.
public void Intercept(IInvocation invocation)
{
var logger = LogManager.GetLogger(invocation.TargetType);
try
{
StringBuilder sb = null;
if (logger.IsDebugEnabled)
{
sb = new StringBuilder(invocation.TargetType.FullName)
.Append(".")
.Append(invocation.Method)
.Append("(");
for (int i = 0; i < invocation.Arguments.Length; i++)
{
if (i > 0)
sb.Append(", ");
sb.Append(invocation.Arguments[i]);
}
sb.Append(")");
logger.Debug(sb);
}
invocation.Proceed();
if (logger.IsDebugEnabled)
{
logger.Debug("Result of " + sb + " is: " + invocation.ReturnValue);
}
}
catch (Exception e)
{
logger.Error(e);
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment