【问题标题】:Log WCF soap message parameters and method name记录 WCF 肥皂消息参数和方法名称
【发布时间】:2014-10-23 02:43:45
【问题描述】:

我正在使用 Log4net 并且有一个方法来记录调用上下文

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);

                }
            }
        }

我想要的是有什么方法可以记录消息方法名称和参数

【问题讨论】:

  • Kamran,你是用什么方案来获取方法和参数的?
  • 我继续我的其他任务,目前已完成手动记录我最需要的参数。所以实际上还没有合适的解决方案

标签: c# wcf


【解决方案1】:

您不能从代码的上下文中检索方法的参数值,只能检索它们的类型。恐怕您想直接做的事情是不可能的。您可以将参数传递给 logging 方法以记录它们的值,也可以使用aspect oriented programming 系统,您感兴趣的函数将包含在您可以定义的一些代码中。

有很多 AOP 解决方案可供选择,我个人喜欢 Castle.Windsor 及其 interceptors

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2011-01-14
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多