c# - 记录 WCF soap 消息参数和方法名称

标签 c# wcf

我正在使用 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);

                }
            }
        }

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

最佳答案

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

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

关于c# - 记录 WCF soap 消息参数和方法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562317/

相关文章:

c# - 如何在 LINQ to 实体表达式中使用 CreateDateTime

c# - 使用 SendMessageTimeout

c# - WCF:在运行时显示 channel 的所有配置参数

c# - 使用 CodeDom/CSharpCodeProvider 输出 C# 别名(int 等)而不是 CLR 类型(Int32 等)

c# - 字符串实习——这段代码应该只在内存中创建 10 个字符串吗?

c# - 这个 NHibernate 查询会影响性能吗?

WCF:如何在 WsHttpBinding 中检测断开连接并获取原始上下文

javascript - 如何在 AngularJS 中创建类似模型绑定(bind)的字典

C# 生成的代理方法与原始 Java 服务方法不同

c# - 多层平台不会检索数据库连接字符串