質問

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