简体   繁体   中英

Log WCF soap message parameters and method name

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM