private static void GetUserData(FlogDetail 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;
        }
Exemple #2
0
        public static void WriteDiagnostic(FlogDetail infoToLog)
        {
            var writeDiagnostics = Convert.ToBoolean(Environment.GetEnvironmentVariable("DIAGNOSTICS_ON"));

            if (!writeDiagnostics)
            {
                return;
            }
            _diagnosticsLogger.Write(LogEventLevel.Information, "{@FlogDetail}", infoToLog);
        }
Exemple #3
0
 public static void WriteError(FlogDetail 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, "{@FlogDetail}", infoToLog);
 }
Exemple #4
0
 public static void WritePerf(FlogDetail infoToLog)
 {
     //_perfLogger.Write(LogEventLevel.Information, "{@FlogDetail}", infoToLog);
     _perfLogger.Write(LogEventLevel.Information,
                       "{Timestamp}{Message}{Layer}{Location}{Product}" +
                       "{CustomException}{ElapsedMilliseconds}{Exception}{Hostname}" +
                       "{UserId}{UserName}{CorrelationId}{AdditionalInfo}",
                       infoToLog.Timestamp, infoToLog.Message,
                       infoToLog.Layer, infoToLog.Location,
                       infoToLog.Product, infoToLog.CustomException,
                       infoToLog.ElapsedMilliseconds, infoToLog.Exception?.ToBetterString(),
                       infoToLog.Hostname, infoToLog.UserId,
                       infoToLog.UserName, infoToLog.CorrelationId,
                       infoToLog.AdditionalInfo
                       );
 }
        public PerfTracker(string name, string userId, string userName,
                           string location, string product, string layer)
        {
            _infoToLog = new FlogDetail()
            {
                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) }
            };
        }
        private static void GetRequestData(FlogDetail 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 = QueryHelpers.ParseQuery(request.QueryString.ToString());
                foreach (var key in qdict.Keys)
                {
                    detail.AdditionalInfo.Add($"QueryString-{key}", qdict[key]);
                }
            }
        }
        public static FlogDetail GetWebFlogDetail(string product, string layer, string activityName,
                                                  HttpContext context, Dictionary <string, object> addtionalInfo = null)
        {
            var detail = new FlogDetail()
            {
                Product        = product,
                Layer          = layer,
                Message        = activityName,
                Hostname       = Environment.MachineName,
                CorrelationId  = Activity.Current?.Id ?? context.TraceIdentifier,
                AdditionalInfo = addtionalInfo ?? new Dictionary <string, object>()
            };

            GetUserData(detail, context);
            GetRequestData(detail, context);
            // Session data??
            // Cookie data??
            return(detail);
        }
        public PerfTracker(FlogDetail 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));
            }
        }
Exemple #9
0
 public static void WriteError(FlogDetail 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, "{@FlogDetail}", infoToLog);
     _errorLogger.Write(LogEventLevel.Information,
                        "{Timestamp}{Message}{Layer}{Location}{Product}" +
                        "{CustomException}{ElapsedMilliseconds}{Exception}{Hostname}" +
                        "{UserId}{UserName}{CorrelationId}{AdditionalInfo}",
                        infoToLog.Timestamp, infoToLog.Message,
                        infoToLog.Layer, infoToLog.Location,
                        infoToLog.Product, infoToLog.CustomException,
                        infoToLog.ElapsedMilliseconds, infoToLog.Exception?.ToBetterString(),
                        infoToLog.Hostname, infoToLog.UserId,
                        infoToLog.UserName, infoToLog.CorrelationId,
                        infoToLog.AdditionalInfo
                        );
 }
Exemple #10
0
        public static void WriteDiagnostic(FlogDetail infoToLog)
        {
            var writeDiagnostics = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableDiagnostics"]);

            if (!writeDiagnostics)
            {
                return;
            }

            //_diagnosticLogger.Write(LogEventLevel.Information, "{@FlogDetail}", infoToLog);
            _diagnosticLogger.Write(LogEventLevel.Information,
                                    "{Timestamp}{Message}{Layer}{Location}{Product}" +
                                    "{CustomException}{ElapsedMilliseconds}{Exception}{Hostname}" +
                                    "{UserId}{UserName}{CorrelationId}{AdditionalInfo}",
                                    infoToLog.Timestamp, infoToLog.Message,
                                    infoToLog.Layer, infoToLog.Location,
                                    infoToLog.Product, infoToLog.CustomException,
                                    infoToLog.ElapsedMilliseconds, infoToLog.Exception?.ToBetterString(),
                                    infoToLog.Hostname, infoToLog.UserId,
                                    infoToLog.UserName, infoToLog.CorrelationId,
                                    infoToLog.AdditionalInfo
                                    );
        }
Exemple #11
0
 public static void WriteUsage(FlogDetail infoToLog)
 {
     _usageLogger.Write(LogEventLevel.Information, "{@FlogDetail}", infoToLog);
 }
Exemple #12
0
 public static void WritePerf(FlogDetail infoToLog)
 {
     _perfLogger.Write(LogEventLevel.Information, "{@FlogDetail}", infoToLog);
 }