I have a asp.net web service application (asmx). NLog has been configured on the project. I want to add the caller's ip address in the logfile. I need to access the REMOTE_ADDR property from within the nlog config file. This is what I tried.

<target name="file" xsi:type="File"
          layout="${longdate} ${logger} ${callsite} ${asp-request:item=REMOTE_ADDR} ${message}"
          fileName="${basedir}/logs/${shortdate}.log" />

the renderer ${asp-request:item=REMOTE_ADDR} should have done the trick. But nothing happens. What am I missing?

Note : I have added reference to the NLog.Extended.dll to the project.

Any help would be appreciated, please.

有帮助吗?

解决方案

You've probably worked it out by now, but the code you were looking for is:

${aspnet-request:serverVariable=remote_addr}

其他提示

As a side note using:

${ aspnet-request:serverVariable = remote_addr }

Produced the following error:

LayoutRenderer cannot be found: 'aspnet-request'

You have to install NLog.Web to make this work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top