private void SetAuthenticatedUserProperty(HttpContext httpContext) { var httpUser = httpContext.User; var userId = httpUser.FindFirstValue(ClaimTypes.NameIdentifier); var userName = httpUser.FindFirstValue(ClaimTypes.Name); var userEmail = httpUser.FindFirstValue(ClaimTypes.Email); var logUser = new LogUser() { Id = userId, UserName = userName, Email = userEmail }; LogContext.PushProperty("User", JsonSerializer.Serialize(logUser)); }
private void SetUnauthenticatedUserProperty(IDictionary <string, object> parameters, ActionDescriptor actionName) { var logUser = new LogUser(); actionName.RouteValues.TryGetValue("action", out string actionNameString); if (actionNameString == "Login") { var model = (LoginParams)parameters["model"]; logUser.Email = model.Email; LogContext.PushProperty("User", JsonSerializer.Serialize(logUser)); } else { var model = (RegisterParams)parameters["model"]; logUser.Email = model.Email; logUser.UserName = model.UserName; LogContext.PushProperty("User", JsonSerializer.Serialize(logUser)); } }