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

2
  • Kamran, what solution did you use for getting the method and parameters? Commented Sep 22, 2014 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 Commented Sep 23, 2014 at 12:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.