【发布时间】:2016-11-21 08:02:11
【问题描述】:
我使用“NLog.Extensions.Logging”进行日志记录,需要记录用户身份,发现可以使用“NLog.Web.AspNetCore”。 “nlog.config”文件被配置为记录“aspnet-user-identity”。但是,当我查看日志时,用户身份部分始终是空字符串,其他列看起来还不错。我错过了什么吗?
我的配置文件的一部分在这里:
<extensions>
<assembly="NLog.Web.AspNetCore" />
</extensions>
<parameter name="@identity" layout="${aspnet-user-identity}"/>
<logger name="*" minlevel="Trace" appendTo="database"/>
插入命令使用“@identity”参数将日志插入数据库,但它总是像我说的那样为空。
【问题讨论】:
-
您是否在 startup.cs 中调用了
app.AddNLogWeb();?见github.com/NLog/NLog.web -
是的,我已经调用了@Julian 方法,忘记将其添加到我的问题中。
-
它使用
context.User.Identity.Name,其中context是GetService<IHttpContextAccessor>()。你能检查一下它是否仍然有效吗?
标签: asp.net-core-mvc nlog