private static void GetUserData(EnvyLogDetail detail, 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) { if (claim.Type == ClaimTypes.NameIdentifier) { userId = claim.Value; } else if (claim.Type == "name") { userName = claim.Value; } else { // example dictionary key: UserClaim-4-role detail.AdditionalInfo.Add($"UserClaim-{i++}-{claim.Type}", claim.Value); } } } detail.UserId = userId; detail.UserName = userName; }
public static EnvyLogDetail GetWebFlogDetail(string product, string layer, string activityName, HttpContext context, Dictionary <string, object> additionalInfo = null) { var detail = new EnvyLogDetail { Product = product, Layer = layer, Message = activityName, Hostname = Environment.MachineName, CorrelationId = Activity.Current?.Id ?? (context != null ? context.TraceIdentifier : Guid.NewGuid().ToString("n")), AdditionalInfo = additionalInfo ?? new Dictionary <string, object>() }; if (context != null) { GetUserData(detail, context); GetRequestData(detail, context); } // Session data?? // Cookie data?? return(detail); }
public static void WriteDiagnostic(EnvyLogDetail infoToLog) { var writeDiagnostics = Convert.ToBoolean(Environment.GetEnvironmentVariable("DIAGNOSTICS_ON")); if (!writeDiagnostics) { return; } _diagnosticLogger.Write(LogEventLevel.Information, "{@PipelineSpaceLogDetail}", infoToLog); }
public static void WriteError(EnvyLogDetail infoToLog) { if (infoToLog.Exception != null) { var procName = FindProcName(infoToLog.Exception); infoToLog.Location = string.IsNullOrEmpty(procName) ? infoToLog.Location : procName; infoToLog.Message = GetMessageFromException(infoToLog.Exception); } _errorLogger.Write(LogEventLevel.Information, "{@PipelineSpaceLogDetail}", infoToLog); }
private static void GetRequestData(EnvyLogDetail detail, HttpContext context) { var request = context.Request; if (request != null) { detail.Location = request.Path; detail.AdditionalInfo.Add("UserAgent", request.Headers["User-Agent"]); // non en-US preferences here?? detail.AdditionalInfo.Add("Languages", request.Headers["Accept-Language"]); var qdict = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(request.QueryString.ToString()); foreach (var key in qdict.Keys) { detail.AdditionalInfo.Add($"QueryString-{key}", qdict[key]); } } }
public EnvyPerformanceTracker(string name, string userId, string userName, string location, string product, string layer) { _infoToLog = new EnvyLogDetail() { Message = name, UserId = userId, UserName = userName, Product = product, Layer = layer, Location = location, Hostname = Environment.MachineName }; var beginTime = DateTime.Now; _infoToLog.AdditionalInfo = new Dictionary <string, object>() { { "Started", beginTime.ToString(CultureInfo.InvariantCulture) } }; }
public EnvyPerformanceTracker(EnvyLogDetail details) { _sw = Stopwatch.StartNew(); _infoToLog = details; var beginTime = DateTime.Now; if (_infoToLog.AdditionalInfo == null) { _infoToLog.AdditionalInfo = new Dictionary <string, object>() { { "Started", beginTime.ToString(CultureInfo.InvariantCulture) } } } ; else { _infoToLog.AdditionalInfo.Add( "Started", beginTime.ToString(CultureInfo.InvariantCulture)); } }
public static void WriteUsage(EnvyLogDetail infoToLog) { _usageLogger.Write(LogEventLevel.Information, "{@PipelineSpaceLogDetail}", infoToLog); }