Está en la página 1de 3

#region Excepciones MSSQL /// <summary> /// Recupera el destino del publicador de envio de correos.

/// </summary> /// <returns>Destino del correo.</returns> public static String RutaFicheroLOG() { //Mensaje. String MessageError = msgError + rutaLOG + "[" + "RutaLOG" + "]."; try { NameValueCollection config = (NameValueCollection)ConfigurationM anager.GetSection(rutaLOG); if (config == null) { throw new ConfigurationErrorsException("Seccin " + rutaLOG); } String ruta = config["RutaLOG"]; if (String.IsNullOrEmpty(ruta)) { throw new ConfigurationErrorsException("RutaLOG es nulo o va co"); } return HttpContext.Current.Server.MapPath("~" + Path.AltDirector ySeparatorChar + ruta); } catch (ConfigurationErrorsException confEx) { //Mensaje. MessageError = MessageError + confEx.Message; // Log Excepcin WebExceptionEvent evento = new WebExceptionEvent(MessageError, n ull, 100061, confEx); evento.Raise(); //Subir Excepcin. throw new ConfigurationErrorsException(MessageError, confEx); } catch (HttpException httpEx) { //Mensaje. MessageError = MessageError + httpEx.Message; // Log Excepcin WebExceptionEvent evento = new WebExceptionEvent(MessageError, n ull, 100015, httpEx); evento.Raise(); //Subir Excepcin. throw new ConfigurationErrorsException(MessageError, httpEx); } catch (SystemException ex) { //Mensaje. MessageError = MessageError + ex.Message; // Log Excepcin WebExceptionEvent evento = new WebExceptionEvent(MessageError, n

ull, 100062, ex); evento.Raise(); //Subir Excepcin. throw new ConfigurationErrorsException(MessageError, ex); } } private static bool crearLOG(string rutaLOG) { try { // Creamos el XML con un nodo XDocument miXML = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("LOG")); miXML.Save(rutaLOG); return true; } catch (Exception e) { string err = e.ToString(); return false; } } private class Parametros { public string campo { get; set; } public string tipo { get; set; } public string valor { get; set; } } private void LogConsultaXML(String consulta) { NameValueCollection rutaLOG = (NameValueCollection)ConfigurationMana ger.GetSection("ArquitecturaWeb/Excepciones"); string nomFichero = HttpContext.Current.Server.MapPath(rutaLOG["ruta LOG"] + "LOGSql.xml"); try { if (!File.Exists(nomFichero)) { crearLOG(nomFichero); } List<Parametros> parametros = new List<Parametros>(); if(XMLParametrizado) { foreach (SqlParameter p in ParametrosSQL) { Parametros param = new Parametros(); if (p != null) { switch (p.ParameterName) { case "DateTime": param.campo = p.ParameterName.ToString(); param.tipo = p.SqlDbType.ToString(); break; default: param.campo = p.ParameterName.ToString(); param.tipo = p.SqlDbType.ToString() + "(" + p.Size + ")"; break; } if (p.Value == null)

{ param.valor = "null"; } else { param.valor = p.Value.ToString(); } parametros.Add(param); } } } XDocument XML = XDocument.Load(nomFichero); XML.Root.Add ( new XElement("Errores", new XElement("Fecha", DateTime.Now.ToString()), new XElement("Fichero", XMLQueryFileID.ToString().Tr im()), new XElement("Transaccion", XMLQueryIdTransaccion.To String().Trim()), new XElement("Consulta", consulta.ToString().Trim()) , new XElement("Parametros", from datos in parametros select new XElement("Parametro", new XAttribute("Campo", datos.campo), new XAttribute("Tipo", datos.tipo), new XAttribute("Valor", datos.valor) ) ) ) ); XML.Save(nomFichero); } catch (Exception e) { string err = e.ToString(); } } #endregion

También podría gustarte