Reputation: 3763
I have been trying to log server details using nlog. But seems like there is some errors in layout renderer.
I have tried these:
<parameter name="@serverName" layout="${aspnet-request:serverVariable=SERVER_NAME}" />
<parameter name="@port" layout="${aspnet-request:serverVariable=SERVER_PORT}" />
<parameter name="@serverAddress" layout="${aspnet-request:serverVariable=LOCAL_ADDR}" />
<parameter name="@remoteAddress" layout="${aspnet-request:serverVariable=REMOTE_ADDR}:${aspnet-request:serverVariable=REMOTE_PORT}" />
These are from official documentation but still these are not working.
I have these in project.json file
"NLog.Extensions.Logging": "1.0.0-rtm-beta1",
"NLog.Web.AspNetCore": "4.3.0",
Upvotes: 0
Views: 2146
Reputation: 36790
As stated in the docs, the serverVariable
option for ${aspnet-request}
isn't supported in ASP.NET Core
serverVariable - ServerVariables item to be rendered. See for possible options: msdn. Not supported in ASP.NET Core.
There isn't a Server Variables collection in ASP.NET Core (in contract with ASP.NET), so we cannot use it.
We have replaced several constructions with new renderers, see this overview
${aspnet-request:serverVariable=SERVER_NAME}
=> Is this ${aspnet-Request-Host}
? ${aspnet-request:serverVariable=SERVER_PORT}
=> ${aspnet-request-url:IncludeHost=false:IncludePort=true}
${aspnet-request:serverVariable=LOCAL_ADDR}
=> I think - ${aspnet-request-url}
${aspnet-request:serverVariable=REMOTE_ADDR}
=> don't think this one is supported. Update: if you need the IP, see How to configure NLog to get IP address .NET Core
Upvotes: 1