【问题标题】:Logging IP Address in WCF Service在 WCF 服务中记录 IP 地址
【发布时间】:2013-05-08 14:27:48
【问题描述】:

我在我的 WCF 服务中使用 NLog,并且想记录调用者的 IP 地址。

我尝试过使用 aspnet-LayoutRenderers(${aspnet-request:serverVariable=remote_host}${aspnet-request:serverVariable=remote_addr},但无济于事,因为抛出了内部 NLog 异常并且没有生成日志文件。

有没有办法在 WCF 服务中记录 IP 地址,而无需将其作为参数传递给被调用的方法?

【问题讨论】:

    标签: c# wcf ip-address nlog


    【解决方案1】:
    var msg = OperationContext.Current
              .IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    
    var address = msg.Address;
    

    【讨论】:

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