Пример #1
0
        /// <summary>
        /// Inserts the app exception.
        /// </summary>
        /// <param name="model">The model.</param>
        public void InsertAppException(MAppException model)
        {
            MySqlConnection conn = ConnectionFactory.LogExceptionWrite;
            try
            {
                string sql = string.Format(
            @"INSERT INTO AppException{0}(LogID,TrackID,ErrorCode,ExceptionLevel,ApplicationName,LocalIP,ExceptionMsg,ExceptionContext,OrginalExceptionMsg)
            VALUES(@LogID,@TrackID,@ErrorCode,@ExceptionLevel,@ApplicationName,@LocalIP,@ExceptionMsg,@ExceptionContext,@OrginalExceptionMsg);",
                                                                                                                                   model.TimePoint.ToString("yyyyMMdd"));

                model.LogID = Guid.NewGuid().ToString();
                MySqlParameter[] param =
                {
                     new MySqlParameter("@LogID", MySqlDbType.VarChar) { Value = model.LogID },
                     new MySqlParameter("@TrackID", MySqlDbType.VarChar) { Value = model.TrackID },
                     new MySqlParameter("@ErrorCode", MySqlDbType.VarChar) { Value = model.ErrorCode },
                     new MySqlParameter("@ExceptionLevel", MySqlDbType.Int32) { Value = (int)model.ExceptionLevel },
                     new MySqlParameter("@ApplicationName", MySqlDbType.VarChar) { Value = model.ApplicationName },
                     new MySqlParameter("@LocalIP", MySqlDbType.VarChar) { Value = model.LocalIP },
                     new MySqlParameter("@ExceptionMsg", MySqlDbType.VarChar) { Value = model.ExceptionMsg },
                     new MySqlParameter("@ExceptionContext", MySqlDbType.VarChar) { Value = model.ExceptionContext },
                     new MySqlParameter("@OrginalExceptionMsg", MySqlDbType.VarChar) { Value = model.OrginalExceptionMsg },
                };
                if (conn != null)
                {
                    if (conn.State != System.Data.ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    MySqlHelper.ExecuteNonQuery(conn, sql, param);
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Writes the app exception.
        /// </summary>
        /// <param name="appex">The appex.</param>
        /// <param name="timepoint">The timepoint.</param>
        /// <param name="routeModuleName">Name of the route module.</param>
        public void WriteAppException(AppException appex, DateTime timepoint, string routeModuleName)
        {
            try
            {
                string trackID = appex.Data["TrackID"] as string;
                Dictionary<string, object> parameters = new Dictionary<string, object>();

                if (appex.Data != null)
                {
                    foreach (var key in appex.Data.Keys)
                    {
                        if (key is string)
                        {
                            string keyStr = key as string;
                            parameters.Add(keyStr, appex.Data[key]);
                        }
                    }
                }

                string originalException = appex.InnerException != null ? appex.InnerException.Message : string.Empty;
                string exceptionContext = JsonHelper.JsonSerializer<Dictionary<string, object>>(parameters);
                string localip = IPAddressHelper.GetLocalIpAddress();
                MAppException mappex = new MAppException()
                {
                    OrginalExceptionMsg = originalException,
                    ExceptionContext = exceptionContext,
                    ExceptionMsg = appex.ToString(),
                    ErrorCode = appex.ErrorCode,
                    LocalIP = localip,
                    ApplicationName = AppKeySettings.ApplicationName,
                    LogID = Guid.NewGuid().ToString(),
                    TrackID = trackID,
                    TimePoint = DateTime.Now,
                    ExceptionLevel = appex.Level,
                };

                DALFactory.GetAppExceptionDAL(LogRecordType.DBLog).InsertAppException(mappex);
            }
            catch (Exception ex)
            {
                TextDataAccess.AddLog(ex.StackTrace.ToString());
            }
        }