2

I am using Log4net and have a method to log the calling context

private void LogCallingProgramContext()
        {
            OperationContext context = OperationContext.Current;
            if (context != null)
            {
                MessageProperties messageProperties = context.IncomingMessageProperties;
                var endpointProperty =
                    messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                if (endpointProperty != null)
                {

                    string strCallingProgramContext = string.Format("Call from IP address {0} and port is {1}", endpointProperty.Address, endpointProperty.Port);
                    Logger.Info(strCallingProgramContext);

                }
            }
        }

What i want is that is there any way that i can log the message method name and the parameters

Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93
  • Kamran, what solution did you use for getting the method and parameters? – samy Sep 22 '14 at 10:22
  • I move on to my other tasks and at the moment done Manual logging of the parameters which i required most. So In real no proper solution yet – Kamran Shahid Sep 23 '14 at 12:29

1 Answers1

0

You cannot retrieve the parameter values for the method from the context of the code, only their types. I'm afraid what you want to do is not possible directly. You can either pass the parameters to the logging method in order to log their values or you can use an aspect oriented programming system where the functions you are interested in will be wrapped in some code that you can define.

There are plenty of AOP solutions to choose from, I personnally like Castle.Windsor and its interceptors.

Community
  • 1
  • 1
samy
  • 14,832
  • 2
  • 54
  • 82