示例#1
0
        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;
        }
示例#2
0
        public static void WriteDiagnostic(HippoLogDetail infoToLog)
        {
            var writeDiagnostics = Convert.ToBoolean(Environment.GetEnvironmentVariable("DIAGNOSTICS_ON"));

            if (!writeDiagnostics)
            {
                return;
            }

            _diagnosticLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", infoToLog);
        }
示例#3
0
 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);
 }
示例#4
0
        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));
            }
        }
示例#5
0
        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]);
                }
            }
        }
示例#6
0
        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) }
            };
        }
示例#7
0
        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);
        }
示例#8
0
 public static void WriteUsage(HippoLogDetail hippoLogDetail)
 {
     _usageLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", hippoLogDetail);
 }
示例#9
0
 public static void WritePerf(HippoLogDetail hippoLogDetail)
 {
     _perfLogger.Write(LogEventLevel.Information, "{@HippoLogDetail}", hippoLogDetail);
 }