Pregunta

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.

¿Fue útil?

Solución

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

${aspnet-request:serverVariable=remote_addr}

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top