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