Home > Enterprise >  None of the NLog AspNetRequest layour renderers are working for ASP.NET 4.6 web forms app
None of the NLog AspNetRequest layour renderers are working for ASP.NET 4.6 web forms app

Time:12-22

I am not getting any values for the AspNetRequest layout renderers in an ASP.NET 4.6.2 Framework Web Forms app.

https://github.com/NLog/NLog/wiki/AspNetRequest-layout-renderer

All three of the following and several others that I have tried are all empty strings. Is there some global switch I need to enable within NLog to get these to work?

dbTarget.Parameters.Add(new DatabaseParameterInfo("@VisitedPage", "${aspnet-request-host}"));
dbTarget.Parameters.Add(new DatabaseParameterInfo("@PageURL", "${aspnet-appbasepath}"));
dbTarget.Parameters.Add(new DatabaseParameterInfo("@ReferrerURL", "${aspnet-request:header=Referer}"));

CodePudding user response:

NLog v5 no longer automatically scan and load extension assemblies. This means NLog.Web-LayoutRenderers are not available by default.

Instead one have manually register NLog.Web extensions. This can be done in NLog.config:

<extensions>
   <add assembly="NLog.Web" />
</extensions>

Or it can also be done from code (before starting to build dbTarget):

LogManager.Setup().RegisterNLogWeb()

See also: https://github.com/NLog/NLog/wiki/Fluent-Configuration-API

  • Related