Пример #1
0
        /// <summary>
        /// Exceptions the value tracker.
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="parameters">The parameters.</param>
        public static void ExceptionValueTracker(this Exception ex, IDictionary <string, object> parameters)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("[Application Error Starts]");

            foreach (KeyValuePair <string, object> item in parameters)
            {
                string paramValue = (item.Value.GetType().Namespace.StartsWith("System")) ?
                                    item.Value.ToString() : JsonConvert.SerializeObject(item.Value, new JsonSerializerSettings
                {
                    Formatting            = Newtonsoft.Json.Formatting.Indented,
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                });

                sb.AppendLine(string.Format("   {0} : {1}", item.Key, paramValue));
            }
            sb.AppendLine("[Application Error Ends]");

            ex.Data.Clear();
            ex.Data.Add("FunctionInfo", sb.ToString());

            if (ConfigurationManager.AppSettings["EnableErrorLog"].ToString().ToLower() == "true")
            {
                StackLogger.LogMessage(ex.ToString());
                LogToFileWithStack(string.Format("{0}\r\n{1}", StackLogger.GetCurrentLog(), sb.ToString()));
            }
        }
Пример #2
0
        /// <summary>
        /// Exceptions the value tracker.
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="parameters">The parameters.</param>
        public static void ExceptionValueTracker(this Exception ex, params object[] parameters)
        {
            StackFrame stackFrame = new StackTrace().GetFrame(1);
            var        methodInfo = stackFrame.GetMethod();
            var        paramInfos = methodInfo.GetParameters();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("[Function: {0}.{1}]", methodInfo.DeclaringType.FullName, methodInfo.Name));
            for (int i = 0; i < paramInfos.Length; i++)
            {
                var currentParameterInfo = paramInfos[i];

                string paramValue = string.Empty;
                if (parameters.Length - 1 >= i)
                {
                    var currentParameter = parameters[i];
                    if (parameters[i] != null)
                    {
                        paramValue = (currentParameter.GetType().Namespace.StartsWith("System")) ?
                                     currentParameter.ToString() : JsonConvert.SerializeObject(currentParameter,
                                                                                               new JsonSerializerSettings
                        {
                            Formatting            = Newtonsoft.Json.Formatting.Indented,
                            ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                        });
                    }
                }

                sb.AppendLine(string.Format("   {0} : {1}", currentParameterInfo.Name, paramValue));
            }
            sb.AppendLine("[Function End]");

            ex.Data.Clear();
            ex.Data.Add("FunctionInfo", sb.ToString());

            if (ConfigurationManager.AppSettings["EnableErrorLog"].ToString().ToLower() == "true")
            {
                StackLogger.LogMessage(ex.ToString());
                LogToFileWithStack(string.Format("{0}\r\n{1}", StackLogger.GetCurrentLog(), sb.ToString()));
            }
        }