private static void GetUserData(HippoLogDetail hippoLogDetail, HttpContext context) { var userId = ""; var userName = ""; var user = context.User; // ClaimsPrincipal.Current is not sufficient if (user != null) { var i = 1; // i included in dictionary key to ensure uniqueness foreach (var claim in user.Claims) { switch (claim.Type) { case ClaimTypes.NameIdentifier: userId = claim.Value; break; case "name": userName = claim.Value; break; default: // example dictionary key: UserClaim-4-role hippoLogDetail.AdditionalInfo.Add($"UserClaim-{i++}-{claim.Type}", claim.Value); break; } } } hippoLogDetail.UserId = userId; hippoLogDetail.UserName = userName; }
public static void WriteDiagnostic(HippoLogDetail infoToLog) { var writeDiagnostics = Convert.ToBoolean(Environment.GetEnvironmentVariable("DIAGNOSTICS_ON")); if (!writeDiagnostics) { return; } _diagnosticLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", infoToLog); }
public static void WriteError(HippoLogDetail hippoLogDetail) { if (hippoLogDetail.Exception != null) { var procName = FindProcName(hippoLogDetail.Exception); hippoLogDetail.Location = string.IsNullOrEmpty(procName) ? hippoLogDetail.Location : procName; hippoLogDetail.Message = GetMessageFromException(hippoLogDetail.Exception); } _errorLogger.Write(LogEventLevel.Information, "{@FlogDetail}", hippoLogDetail); }
public PerfTracker(HippoLogDetail hippoLogDetail) { _sw = Stopwatch.StartNew(); _hippoLogDetail = hippoLogDetail; var beginTime = DateTime.Now; if (_hippoLogDetail.AdditionalInfo == null) { _hippoLogDetail.AdditionalInfo = new Dictionary <string, object>() { { "Started", beginTime.ToString(CultureInfo.InvariantCulture) } }; } else { _hippoLogDetail.AdditionalInfo.Add("Started", beginTime.ToString(CultureInfo.InvariantCulture)); } }
private static void GetRequestData(HippoLogDetail hippoLogDetail, HttpContext context) { var request = context.Request; if (request != null) { hippoLogDetail.Location = request.Path; hippoLogDetail.AdditionalInfo.Add("UserAgent", request.Headers["User-Agent"]); // non en-US preferences here?? hippoLogDetail.AdditionalInfo.Add("Languages", request.Headers["Accept-Language"]); var qdict = Microsoft.AspNetCore.WebUtilities .QueryHelpers.ParseQuery(request.QueryString.ToString()); foreach (var key in qdict.Keys) { hippoLogDetail.AdditionalInfo.Add($"QueryString-{key}", qdict[key]); } } }
public PerfTracker(string name, string userId, string userName, string location, string product, string layer) { _hippoLogDetail = new HippoLogDetail() { Message = name, UserId = userId, UserName = userName, Product = product, Layer = layer, Location = location, Hostname = Environment.MachineName }; var beginTime = DateTime.Now; _hippoLogDetail.AdditionalInfo = new Dictionary <string, object>() { { "Started", beginTime.ToString(CultureInfo.InvariantCulture) } }; }
public static HippoLogDetail GetWebFlogDetail(string product, string layer, string activityName, HttpContext context, Dictionary <string, object> additionalInfo = null) { var detail = new HippoLogDetail { Product = product, Layer = layer, Message = activityName, Hostname = Environment.MachineName, CorrelationId = Activity.Current?.Id ?? context.TraceIdentifier, AdditionalInfo = additionalInfo ?? new Dictionary <string, object>() }; GetUserData(detail, context); GetRequestData(detail, context); // Session data?? // Cookie data?? return(detail); }
public static void WriteUsage(HippoLogDetail hippoLogDetail) { _usageLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", hippoLogDetail); }
public static void WritePerf(HippoLogDetail hippoLogDetail) { _perfLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", hippoLogDetail); }