コード例 #1
0
        /// <summary>
        /// Gather details about current user associate with this HTTP pipeline request.
        /// </summary>
        private static void GetUserData(PioneerLog detail, HttpContext context)
        {
            var userId   = "";
            var userName = "";
            var user     = context.User;

            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:
                        detail.AdditionalInfo.Add($"UserClaim-{i++}-{claim.Type}", claim.Value);
                        break;
                    }
                }
            }

            detail.UserId   = userId;
            detail.Username = userName;
        }
コード例 #2
0
        /// <summary>
        /// Get as <see cref="PioneerLog"/> object pre-populated with details parsed
        /// from the ASP.NET Core environment.
        /// </summary>
        public static PioneerLog GetTubDetail(string message,
                                              HttpContext context = null,
                                              Dictionary <string, object> additionalInfo = null)
        {
            var detail = new PioneerLog
            {
                Id = Guid.NewGuid(),
                ApplicationName             = Configuration.ApplicationName,
                ApplicationLayer            = Configuration.ApplicationLayer,
                Message                     = message,
                Hostname                    = Environment.MachineName,
                CorrelationId               = IsNullOrEmpty(CorrelationId) ? Guid.NewGuid().ToString() : CorrelationId,
                SystemGenerateCorrelationId = IsNullOrEmpty(CorrelationId),
                AdditionalInfo              = additionalInfo ?? new Dictionary <string, object>(),
                CreationTimestamp           = DateTime.UtcNow
            };

            if (context == null)
            {
                return(detail);
            }

            GetUserData(detail, context);
            GetRequestData(detail, context);

            return(detail);
        }
コード例 #3
0
        private static void ExtractQueryStringIntoAdditionalInfo(PioneerLog detail, HttpContext context)
        {
            var qdict = QueryHelpers.ParseQuery(context.Request.QueryString.ToString());

            foreach (var key in qdict.Keys)
            {
                detail.AdditionalInfo.Add($"QueryString-{key}", qdict[key]);
            }
        }
コード例 #4
0
        /// <summary>
        /// Gather details about the request made to this HTTP pipeline request.
        /// </summary>
        private static void GetRequestData(PioneerLog detail, HttpContext context)
        {
            if (context.Request == null)
            {
                return;
            }

            detail.ApplicationLocation = context.Request.Path;
            detail.AdditionalInfo.Add("UserAgent", context.Request.Headers["User-Agent"]);
            detail.AdditionalInfo.Add("Languages", context.Request.Headers["Accept-Language"]);

            ExtractQueryStringIntoAdditionalInfo(detail, context);
        }
コード例 #5
0
        public PioneerLogsPerformanceTracker(PioneerLog details)
        {
            _sw  = Stopwatch.StartNew();
            _log = details;

            var beginTime = DateTime.Now;

            if (_log.AdditionalInfo == null)
            {
                _log.AdditionalInfo = new Dictionary <string, object>
                {
                    { "Started", beginTime.ToString(CultureInfo.InvariantCulture) }
                };
            }
            else
            {
                _log.AdditionalInfo.Add("Started", beginTime.ToString(CultureInfo.InvariantCulture));
            }
        }