private LoggingModel GetLogModelAsJsonString(HttpContext context) { var tokenValid = context.Request.Headers.TryGetValue("Authorization", out var token); var accessToken = tokenValid ? token.ToString() : "token not passed"; var model = new LoggingModel { Token = accessToken, RequestPath = context.Request.Path, Method = context.Request.Path, ClientMachineName = Dns.GetHostName(), ClientIp = context.Request.Host.Value, Host = context.Request.Host.ToString(), QueryString = context.Request.QueryString.ToString(), User = context.User?.Claims.FirstOrDefault(x => x.Type == "Id")?.Value }; return(model); }
private string StringToJson(LoggingModel model) { var json = JsonConvert.SerializeObject(model, Formatting.Indented, jsonSettings); return(json); }