我正在尝试将Serilog与我的ASP.Net Core 1.0项目一起使用.我似乎无法将当前登录的用户添加到已记录的属性中.
有没有人想出来呢?
我试过这个:
using System.Threading.Tasks;
using Serilog.Context;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System.Security.Claims;
using xxx.Models;
namespace xxx.Utils
{
public class EnrichSerilogContextMiddleware
{
private readonly RequestDelegate _next;
public EnrichSerilogContextMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
var username = httpContext.User.Identity.Name;
if (httpContext.User.Identity.IsAuthenticated)
{
var userFullName = (((ClaimsIdentity)httpContext.User.Identity).FindFirst(Member.FullnameClaimName).Value);
var userName = "anyone@gmail.com";
LoggerEnricher.AddEntryPointContext(userFullName, userName);
}
else
{
LoggerEnricher.AddEntryPointContext();
}
await _next(httpContext);
}
}
public static class LoggerEnricher
{
public static void AddEntryPointContext(string userFullName = null, …Run Code Online (Sandbox Code Playgroud) 您是否知道在Asp.Net Core的剃刀视图上为焦点添加焦点的方法.我知道这可以通过javascript完成,但是还有一个标签吗?在input元素或包含表单元素上.
提前致谢
SørenRokkedal