NLog version: NLog.Web.AspNetCore 4.5.4
Platform: ASP.NET Core 2.1
Current NLog config (xml or C#, if relevant)
<?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">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<target xsi:type="File"
name="allfile"
layout="${longdate}|${event-properties:item=EventId_Id}|${logger}|${aspnet-mvc-controller}|${aspnet-mvc-action}|${aspnet-request-method}|${aspnet-user-indentity}|${uppercase:${level}}|${message} ${exception:format=tostring}"
fileName="logs\logfile-all.log"
archiveFileName="logs\logfile-all.{#}.log"
archiveEvery="Day"
archiveNumbering="DateAndSequence"
archiveDateFormat="yyyy-MM-dd"
maxArchiveFiles="31"
keepFileOpen="true" />
<target xsi:type="File"
name="file"
layout="${longdate}|${event-properties:item=EventId_Id}|${logger}|${aspnet-mvc-controller}|${aspnet-mvc-action}|${aspnet-request-method}|${aspnet-user-indentity}|${uppercase:${level}}|${message} ${exception:format=tostring}"
fileName="logs\logfile.log"
archiveFileName="logs\logfile.{#}.log"
archiveEvery="Day"
archiveNumbering="DateAndSequence"
archiveDateFormat="yyyy-MM-dd"
maxArchiveFiles="31"
keepFileOpen="true" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="allfile" />
<logger name="Microsoft.*" maxLevel="Info" final="true" />
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
public class Program
{
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((context, logging) =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
if (context.HostingEnvironment.IsDevelopment())
{
logging.AddDebug();
}
})
.UseNLog();
// ...
}
public class Startup
{
// ...
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// ...
}
}
2018-06-12 12:57:06.1501 Error Error parsing layout aspnet-user-indentity will be ignored. Exception: System.ArgumentException: LayoutRenderer cannot be found: 'aspnet-user-indentity'. Is NLog.Web not included?
at NLog.Config.Factory`2.CreateInstance(String name)
at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name)
NLog.Web package lists the NLog.Web.AspNetCore as the correct package to use. The dependencies on nuget.org list NLog.Extensions.Logging as required, however that package states its not applicable.@jcasale You have a small spelling error: ${aspnet-user-indentity} should be ${aspnet-user-identity}
Words cannot convey the level of personal failure and shame:) It's now logging the account name...
Most helpful comment
Words cannot convey the level of personal failure and shame:) It's now logging the account name...