简体   繁体   English

在WCF服务中记录IP地址

[英]Logging IP Address in WCF Service

I'm using NLog in my WCF service and would like to log the caller IP-Address. 我在WCF服务中使用NLog,并希望记录呼叫者的IP地址。

I've tried using the aspnet-LayoutRenderers ( ${aspnet-request:serverVariable=remote_host} , ${aspnet-request:serverVariable=remote_addr} , but to no avail, as an internal NLog exception is being thrown and no log file is being generated. 我尝试使用aspnet-LayoutRenderers( ${aspnet-request:serverVariable=remote_host}${aspnet-request:serverVariable=remote_addr} ,但无济于事,因为内部NLog异常被抛出并且没有日志文件正在生成。

Is there a way to log the IP Address in a WCF service, without needing to pass it as a parameter to the called method? 有没有一种方法可以记录WCF服务中的IP地址,而无需将其作为参数传递给被调用的方法?

var msg = OperationContext.Current
          .IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

var address = msg.Address;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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