public static bool GravarErro(Exception ex, int sis_id) { bool ret = false; try { LOG_Erros entity = new LOG_Erros(); entity.sis_id = sis_id; entity.err_descricao = GetErrorMessage(ex); entity.err_erroBase = ex.GetBaseException().Message; entity.err_tipoErro = ex.GetBaseException().GetType().FullName; entity.err_dataHora = DateTime.Now; entity.err_machineName = Environment.MachineName; string strHostName; string clientIPAddress = ""; try { strHostName = System.Net.Dns.GetHostName(); clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString(); } catch { } entity.err_ip = String.IsNullOrEmpty(clientIPAddress) ? "0.0.0.0" : clientIPAddress; LOG_ErrosBO.Save(entity); } catch { } return(ret); }
protected void _dgvLogs_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton btnAlterar = (LinkButton)e.Row.FindControl("_btnAlterar"); if (btnAlterar != null) { btnAlterar.CommandArgument = e.Row.RowIndex.ToString(); Guid err_id = new Guid(_dgvLogs.DataKeys[e.Row.RowIndex].Value.ToString()); LOG_Erros entity = new LOG_Erros { err_id = err_id }; LOG_ErrosBO.GetEntity(entity); string descricao = entity.err_descricao; descricao = descricao.Replace("\r\n", "\\n"); descricao = descricao.Replace("\\", "\\\\"); descricao = descricao.Replace("\\\\n", "\\n"); descricao = descricao.Replace("'", "\""); btnAlterar.OnClientClick = "javascript:ExibirDescricao(this, '" + descricao + "'); return false;"; } } }
protected void _dgvLogs_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Download")) { try { Guid guid = new Guid(e.CommandArgument.ToString()); LOG_Erros entity = new LOG_Erros { err_id = guid }; LOG_ErrosBO.GetEntity(entity); string fileName = String.Format("Log_{0}_{1}_{2}.txt" , entity.err_dataHora.Year , entity.err_dataHora.Month , entity.err_dataHora.Day); List <LOG_Erros> lt = new List <LOG_Erros>(); lt.Add(entity); _Exportar_ArquivoTXT(lt, fileName); } catch (ThreadAbortException) { } catch (Exception err) { ApplicationWEB._GravaErro(err); _lblMessage.Text = UtilBO.GetErroMessage("Erro ao tentar baixar o log de erros.", UtilBO.TipoMensagem.Alerta); } } }
/// <summary> /// Consulta para retornar descrição(reduzida) do tipo de erro /// em um determinado sistema e dia de ocorrência. /// </summary> /// <param name="sis_id">Sistemas que ocorreu o erro</param> /// <param name="data">Data que ocorreu o erro</param> /// <param name="err_tipoErro">Tipo de erro</param> /// <param name="paginado">Paginado</param> /// <param name="currentPage">Página atual</param> /// <param name="pageSize">Total de registros por página</param> /// <param name="totalRecords">Total de registros por página</param> /// <returns>Lista de obejtos LOG_Erros carregado com o resultado da busca</returns> public List <LOG_Erros> Selectby_Busca_TipoErros(int sis_id, DateTime data, string err_tipoErro, int currentPage, int pageSize, out int totalRecords) { List <LOG_Erros> lt = new List <LOG_Erros>(); QuerySelectStoredProcedure qs = new QuerySelectStoredProcedure("NEW_LOG_Erros_Selectby_Busca_TipoErros", this._Banco); try { #region PARAMETROS Param = qs.NewParameter(); Param.DbType = DbType.Int32; Param.ParameterName = "@sis_id"; Param.Size = 4; if (sis_id > 0) { Param.Value = sis_id; } else { Param.Value = DBNull.Value; } qs.Parameters.Add(Param); Param = qs.NewParameter(); Param.DbType = DbType.DateTime; Param.ParameterName = "@Data"; Param.Size = 8; Param.Value = data; qs.Parameters.Add(Param); Param = qs.NewParameter(); Param.DbType = DbType.String; Param.ParameterName = "@err_tipoErro"; Param.Size = 1000; Param.Value = err_tipoErro; qs.Parameters.Add(Param); #endregion totalRecords = qs.Execute(currentPage, pageSize); foreach (DataRow dr in qs.Return.Rows) { LOG_Erros entity = new LOG_Erros(); lt.Add(this.DataRowToEntity(dr, entity)); } return(lt); } catch { throw; } finally { qs.Parameters.Clear(); } }
public static bool GravarErro(Exception ex) { try { string strSisID = CFG_ConfiguracaoBO.SelecionaValorPorChave("appSistemaID"); int sis_id; if (!Int32.TryParse(strSisID, out sis_id)) { sis_id = 1; } LOG_Erros entity = new LOG_Erros(); entity.sis_id = sis_id; entity.err_descricao = GetErrorMessage(ex); entity.err_erroBase = ex.GetBaseException().Message; entity.err_tipoErro = ex.GetBaseException().GetType().FullName; entity.err_dataHora = DateTime.Now; entity.err_machineName = Environment.MachineName; string strHostName; string clientIPAddress = ""; try { strHostName = System.Net.Dns.GetHostName(); clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString(); } catch { } entity.err_ip = String.IsNullOrEmpty(clientIPAddress) ? "0.0.0.0" : clientIPAddress; LOG_ErrosBO.Save(entity); } catch { } return(false); }
/// <summary> /// Consulta para retornar o log de erros de um determinado dia paginado. /// com a descrição do erro completa /// </summary> /// <param name="data">Data da ocorrencia desejada.</param> /// <param name="currentPage">Página atual</param> /// <param name="pageSize">Total de registros por página</param> /// <param name="totalRecords">total de registros da consulta</param> /// <returns>Lista de obejtos LOG_Erros carregado com o resultado da busca</returns> public List <LOG_Erros> SelectBy_dia2(int sis_id, DateTime data, string usu_login, bool paginado, int currentPage, int pageSize, out int totalRecords) { List <LOG_Erros> lt = new List <LOG_Erros>(); QuerySelectStoredProcedure qs = new QuerySelectStoredProcedure("NEW_LOG_Erros_SelectBY_Dia2", this._Banco); try { #region PARAMETROS Param = qs.NewParameter(); Param.DbType = DbType.Int32; Param.ParameterName = "@sis_id"; Param.Size = 4; if (sis_id > 0) { Param.Value = sis_id; } else { Param.Value = DBNull.Value; } qs.Parameters.Add(Param); Param = qs.NewParameter(); Param.DbType = DbType.DateTime; Param.ParameterName = "@Data"; Param.Size = 8; Param.Value = data; qs.Parameters.Add(Param); Param = qs.NewParameter(); Param.DbType = DbType.AnsiString; Param.ParameterName = "@usu_login"; Param.Size = 100; if (!String.IsNullOrEmpty(usu_login)) { Param.Value = usu_login; } else { Param.Value = DBNull.Value; } qs.Parameters.Add(Param); #endregion if (paginado) { totalRecords = qs.Execute(currentPage, pageSize); } else { qs.Execute(); totalRecords = qs.Return.Rows.Count; } foreach (DataRow dr in qs.Return.Rows) { LOG_Erros entity = new LOG_Erros(); lt.Add(this.DataRowToEntity(dr, entity)); } return(lt); } catch { throw; } finally { qs.Parameters.Clear(); } }
/// <summary> /// Salva log de erro no banco de dados. /// Em caso de exceção salva em arquivo teste /// na pasta Log da raiz do site. /// </summary> /// <param name="ex">Exception</param> public new static void _GravaErro(Exception ex) { try { string path = String.Concat(_DiretorioFisico, "Log"); LogError logError = new LogError(path); //Liga o método no delegate para salvar log no banco de dados. logError.SaveLogBD = delegate(string message) { LOG_Erros entity = new LOG_Erros(); try { //Preenche a entidade com os dados necessário entity.err_descricao = message; entity.err_erroBase = ex.GetBaseException().Message; entity.err_tipoErro = ex.GetBaseException().GetType().FullName; entity.err_dataHora = DateTime.Now; if (HttpContext.Current != null) { string infoRequest = ""; try { string naoGravar = SYS_ParametroBO.ParametroValor(SYS_ParametroBO.eChave.LOG_ERROS_CHAVES_NAO_GRAVAR); List <string> listaNaoGravar = new List <string>(naoGravar.Split(';')); bool gravarQueryString; Boolean.TryParse(SYS_ParametroBO.ParametroValor(SYS_ParametroBO.eChave.LOG_ERROS_GRAVAR_QUERYSTRING), out gravarQueryString); if (gravarQueryString) { infoRequest += retornaListaColecao(HttpContext.Current.Request.QueryString, "QueryString", listaNaoGravar); } bool gravarServerVariables; Boolean.TryParse(SYS_ParametroBO.ParametroValor(SYS_ParametroBO.eChave.LOG_ERROS_GRAVAR_SERVERVARIABLES), out gravarServerVariables); if (gravarServerVariables) { infoRequest += retornaListaColecao(HttpContext.Current.Request.ServerVariables, "ServerVariables", listaNaoGravar); } bool gravarParams; Boolean.TryParse(SYS_ParametroBO.ParametroValor(SYS_ParametroBO.eChave.LOG_ERROS_GRAVAR_PARAMS), out gravarParams); if (gravarParams) { infoRequest += retornaListaColecao(HttpContext.Current.Request.Params, "Params", listaNaoGravar); } } catch { } entity.err_descricao = entity.err_descricao + infoRequest; entity.err_ip = HttpContext.Current.Request.UserHostAddress; entity.err_machineName = HttpContext.Current.Server.MachineName; entity.err_caminhoArq = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath; try { entity.err_browser = String.Concat(new[] { HttpContext.Current.Request.Browser.Browser, HttpContext.Current.Request.Browser.MajorVersion.ToString(), HttpContext.Current.Request.Browser.MinorVersionString }); } catch { entity.err_browser = string.Empty; } if (HttpContext.Current.Session != null) { SessionWEB session = (SessionWEB)HttpContext.Current.Session[SessSessionWEB]; if (session != null) { if (session.__UsuarioWEB.Usuario != null) { entity.usu_id = session.__UsuarioWEB.Usuario.usu_id; entity.usu_login = session.__UsuarioWEB.Usuario.usu_login; } if (session.__UsuarioWEB.Grupo != null) { SYS_Sistema sistema = new SYS_Sistema { sis_id = session.__UsuarioWEB.Grupo.sis_id }; SYS_SistemaBO.GetEntity(sistema); entity.sis_id = sistema.sis_id; entity.sis_decricao = sistema.sis_nome; } } } } //Salva o log no banco de dados LOG_ErrosBO.Save(entity); } catch (Exception) { throw; } }; logError.Log(ex, true); } catch { } }