Пример #1
0
        public void InsertException(Exception ex, int acceso = -1, int elemento = 0, SubElemento subElemento = 0, Terciario terciario = 0, Accion accion = 0, SubAccion subAccion = 0)
        {
            try
            {
                SubNivel       subNivel = SubNivel.Base;
                TrazaException traza    = new TrazaException(ex);

                if (ex is UriFormatException)
                {
                    subNivel = SubNivel.UriFormatException;
                }
                if (ex is System.Data.DataException)
                {
                    subNivel = SubNivel.DataException;
                }

                using (var connection = new MySql.Data.MySqlClient.MySqlConnection(_config.GetConnectionString(_connectionString)))
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "INSERT INTO log (IdNivel,IdSubNivel,IdentificadorAcceso,IdElemento,IdSubElemento,IdTerciario,IdAccion,IdSubAccion,Texto) " +
                                              " VALUES ( @IdNivel,@IdSubNivel,@IdentificadorAcceso,@IdElemento,@IdSubElemento,@IdTerciario,@IdAccion,@IdSubAccion,@Texto);";

                        command.Parameters.Add("@IdNivel", MySqlDbType.Int16);
                        command.Parameters.Add("@IdSubNivel", MySqlDbType.Int16);
                        command.Parameters.Add("@IdentificadorAcceso", MySqlDbType.Int16);
                        command.Parameters.Add("@IdElemento", MySqlDbType.Int16);
                        command.Parameters.Add("@IdSubElemento", MySqlDbType.Int16);
                        command.Parameters.Add("@IdTerciario", MySqlDbType.Int16);
                        command.Parameters.Add("@IdAccion", MySqlDbType.Int16);
                        command.Parameters.Add("@IdSubAccion", MySqlDbType.Int16);
                        command.Parameters.Add("@Texto", MySqlDbType.String);

                        command.Parameters["@IdNivel"].Value             = (int)Nivel.Error;
                        command.Parameters["@IdSubNivel"].Value          = (int)subNivel;
                        command.Parameters["@IdentificadorAcceso"].Value = acceso;
                        command.Parameters["@IdElemento"].Value          = elemento;
                        command.Parameters["@IdSubElemento"].Value       = (int)subElemento;
                        command.Parameters["@IdTerciario"].Value         = (int)terciario;
                        command.Parameters["@IdAccion"].Value            = (int)accion;
                        command.Parameters["@IdSubAccion"].Value         = (int)subAccion;
                        command.Parameters["@Texto"].Value = LimitSize(JsonConvert.SerializeObject(traza), 5000);

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
            }
            catch
            {
            }
        }
Пример #2
0
 public TrazaException(Exception ex, int deep = 0)
 {
     if (ex != null)
     {
         this.Type       = ex.GetType().ToString();
         this.Source     = ex.Source;
         this.StackTrace = ex.StackTrace;
         this.TargetSite = ex.TargetSite.ToString();
         this.Data       = JsonConvert.SerializeObject(ex.Data);
         this.Message    = ex.Message;
         if (ex.InnerException != null && deep < MAX_DEEP)
         {
             this.InnerException = new TrazaException(ex.InnerException, deep++);
         }
     }
 }