If you are using an IoC framework such as Windsor you can use AOP (Aspect-oriented programming) to inject a wrapper round your interfaces. You can then log the method call. Here is an example using Windsor and the IInteceptor interface, this is a striped down version of what we use but there are various examples available.
public class LoggingInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Type targetType = invocation.TargetType ?? invocation.Method.DeclaringType;
ILog logger = LogManager.GetLogger(targetType);
//Probably want to check logger.IsDebugEnabled
if(invocation.Arguments.Count() == 0)
{
logger.DebugFormat("Method '{0}' called.", invocation.Method);
}
else
{
var stringBuilder = new StringBuilder("{" + invocation.Arguments.Length + "}");
for (int i = invocation.Arguments.Length - 1; i > 0; i--)
{
stringBuilder.Insert( 0, "{" + i + "}, " );
}
logger.DebugFormat("Method '{0}' called with parameters: " + stringBuilder, new[] { invocation.Method }.Union(invocation.Arguments).ToArray());
}
try
{
invocation.Proceed();
if (invocation.Method.ReturnType != typeof(void))
{
logger.DebugFormat("Method '{0}' returned: {1}", invocation.Method, invocation.ReturnValue);
}
}
catch(Exception ex)
{
logger.Error(string.Format("Method '{0}' threw exception:", invocation.Method), ex);
throw;
}
}
}
Depending on your IoC framework you should be able wire up individual components.
POINT TO NOTE:
This will work for interfaces methods only, it will not wire up the private methods on an object.