网络核心NLog.Web"aspnet-用户身份"是空的? [英] Net Core NLog.Web "aspnet-user-identity" is empty?

查看:207
本文介绍了网络核心NLog.Web"aspnet-用户身份"是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用"NLog.Extensions.Logging"进行日志记录,需要记录用户身份,发现使用"NLog.Web.AspNetCore"可以实现.配置"nlog.config"文件以记录"aspnet-user-identity".但是,当我查看日志时,用户身份部分始终为空字符串,其他列看起来也不错.我想念什么吗?

I was using "NLog.Extensions.Logging" for logging and need to log user identity and found that it is possible with "NLog.Web.AspNetCore". "nlog.config" file is configured to log the "aspnet-user-identity". However, when I look at logs, user identity part is always empty string, the other columns are look pretty good. Am I missing something?

我的配置文件的一部分在这里:

A part of my configuration file is here:

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

<parameter name="@identity" layout="${aspnet-user-identity}"/>

<logger name="*" minlevel="Trace" appendTo="database"/>

然后执行插入命令,将带有"@identity"参数的日志插入到db中,但是就像我说的那样,它始终是空的.

And an insert command insert a log to db with "@identity" parameter, but it is always empty like I said.

推荐答案

我认为我已经找到了问题,

I think I have found the issue,

发生了重大变化,默认情况下,不再注册IHttpContextAccessor服务. (请参阅公告)

There was an breaking change, The IHttpContextAccessor service is not registered by default anymore. (See announcement)

因此添加您的startup.cs:

So add in your startup.cs:

public void ConfigureServices(IServiceCollection Services)
{
    //call this in case you need aspnet-user-authtype/aspnet-user-identity
    services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}

这篇关于网络核心NLog.Web"aspnet-用户身份"是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆