NLog / NLog.Web

NLog integration for ASP.NET & ASP.NET Core 2-8
https://nlog-project.org
BSD 3-Clause "New" or "Revised" License
320 stars 166 forks source link

ArgumentException: LayoutRenderer cannot be found: 'aspnet-request-url'. Is NLog.Web not included? #264

Closed harishkpv closed 6 years ago

harishkpv commented 6 years ago

Hi, Getting the error - ArgumentException: LayoutRenderer cannot be found: 'aspnet-request-url'. Is NLog.Web not included?

Using the following nuget packages. nugetpackages The config file is <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" throwConfigExceptions="true" internalLogLevel="info" internalLogFile="c:\temp\internal-nlog.txt">

harishkpv commented 6 years ago

Hi, I downloaded the code and added in Nlog.Web.Aspnetcore in my solution and added it as a reference in my project. After that, I am not getting the above error. I am just guessing, maybe there is a problem with nuget package - Nlog.Web.Aspnetcore. Please check it. Thanks!

snakefoot commented 6 years ago

NetCoreApp2 should automatically load Nlog.Web.AspNetCore, but NetCoreApp1 needs some help with explicit add assembly. #249 should improve this

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

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

See also https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(csproj---vs2017)

harishkpv commented 6 years ago

Adding extensions in the config file and it worked.

However, I followed the instructions in the example and currently using AspNetCore.All (2.0.6) - just updated from 2.0.5 with target framework >net Core 2.0

Not sure what I am missing. If you need any information from my side to resolve, please let me know.

snakefoot commented 6 years ago

Can you create an example project where it is not working? Since the example project here is working:

https://github.com/NLog/NLog.Web/tree/master/examples/ASP.NET%20Core%202/Visual%20Studio%202017/ASP.NET%20Core%202%20-%20VS2017

timdoke commented 6 years ago

@snakefoot I ran into this issue as well. Before I added the add assembly line, it was erroring. After I added that line, it was no longer erroring, but these attributes don't get populated in my logs..

    <attribute name="requestIp" layout="${aspnet-Request-IP}"/>
    <attribute name="controller" layout="${aspnet-MVC-Controller}"/>
    <attribute name="action" layout="${aspnet-MVC-Action}"/>
    <attribute name="identity" layout="${identity}"/>

I would guess that the problem is it can't find the IHttpContextAccessor -- as I was able to manually populate these properties in a json log class.

snakefoot commented 6 years ago

@timdoke Have you checked the NLog Internal Logger? https://github.com/NLog/NLog/wiki/Internal-Logging

Another good tool is the debugger.

timdoke commented 6 years ago

@snakefoot I had it set to warn and nothing was being populated. I'll change it over to info and see what happens..

Still nothing about these config entries after I switched it to info.. I have a bunch of internal logs that look like this:

2018-04-03 14:31:56.8609 Info Found 41 configuration items 2018-04-03 14:31:56.8729 Info Loading assembly: NLog.Web.AspNetCore 2018-04-03 14:31:56.8729 Info Adding target File Target[jsonFile] 2018-04-03 14:31:56.8729 Info Configured from an XML element in C:\My local path\NLog.config... 2018-04-03 14:31:56.8909 Info Closing old configuration. 2018-04-03 14:31:56.9189 Info Found 41 configuration items

And the main info output is this..

{ "date": "2018-04-03 14:31:57.4259", "level": "INFO", "logger": "MyLoggerName", "aspnetUser": " ", "message": {"ClientId":null,"FunctionName":null,"LoggedInUserId":null,"Message":"Log Test - Status Entry Information Message","ExceptionType":null,"StackTrace":null,"ServerName":"MycomputerName","Url":"0.0.0.1","RouteData":"ServiceStatusController.StatusCheck","JsonInput":null,"CorrelationId":"d2340cd9-8e7a-496f-9d84-255cb556bccd"} }

snakefoot commented 6 years ago

@timdoke Guess you have to use the debugger then. Anyway please let old issues die. Your issue is completely different than this one (Can see it loads NLog.Web.AspNetCore).

timdoke commented 6 years ago

Ok, thanks @snakefoot .. I thought it was highly related as I initially had the same problem -- and then at the end, the original poster said it didn't work and left it at that..

snakefoot commented 6 years ago

@timdoke If you look at how the issue was closed, then you will see it is referenced by a PullRequest, that fixes the issue. Again please let old issues die.

snakefoot commented 6 years ago

@timdoke Try upgrading to Nlog.Extensions.Logging 1.0.1