예제 #1
0
        public static void WriteDiagnostic(LogDetail infoToLog)
        {
            var writeDiagnostics = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableDiagnostics"]);

            if (!writeDiagnostics)
            {
                return;
            }

            //_diagnosticLogger.Write(LogEventLevel.Information, "{@LogDetail}", 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
                                    );
        }
예제 #2
0
        public PerfTracker(string name, string userId, string userName,
                           string location, string product, string layer)
        {
            _sw        = Stopwatch.StartNew();
            _infoToLog = new LogDetail()
            {
                Message   = name,
                UserId    = userId,
                UserName  = userName,
                Timestamp = DateTime.Now,
                Product   = product,
                Layer     = layer,
                Location  = location,
                Hostname  = Environment.MachineName
            };

            var beginTime = DateTime.Now;

            _infoToLog.AdditionalInfo = new Dictionary <string, object>()
            {
                { "Started", beginTime.ToString(CultureInfo.InvariantCulture) }
            };
        }
예제 #3
0
        public static void LogWebDiagnostic(string product, string layer, string message,
                                            Dictionary <string, object> diagnosticInfo = null)
        {
            var writeDiagnostics = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableDiagnostics"]);

            if (!writeDiagnostics)  // doing this to avoid going through all the data - user, session, etc.
            {
                return;
            }

            string userId, userName, location;
            var    webInfo = GetWebFloggingData(out userId, out userName, out location);

            if (diagnosticInfo != null)
            {
                foreach (var key in diagnosticInfo.Keys)
                {
                    webInfo.Add(key, diagnosticInfo[key]);
                }
            }

            var diagInfo = new LogDetail()
            {
                Product        = product,
                Layer          = layer,
                Location       = location,
                Timestamp      = DateTime.Now,
                UserId         = userId,
                UserName       = userName,
                Hostname       = Environment.MachineName,
                CorrelationId  = HttpContext.Current.Session.SessionID,
                Message        = message,
                AdditionalInfo = webInfo
            };

            Logger.WriteDiagnostic(diagInfo);
        }