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); } } }
protected void _dgvDatas_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Select")) { try { int index = int.Parse(e.CommandArgument.ToString()); string sis_id = _dgvDatas.Rows[index].Cells[4].Text.Equals(" ") ? null : _dgvDatas.Rows[index].Cells[4].Text; string data = _dgvDatas.Rows[index].Cells[0].Text; _dgvLogs.PageIndex = 0; odsLogs.SelectParameters.Clear(); odsLogs.SelectParameters.Add("data", TypeCode.DateTime, data); odsLogs.SelectParameters.Add("sis_id", TypeCode.Int32, sis_id); odsLogs.SelectParameters.Add("usu_login", TypeCode.String, _txtUsuario.Text); odsLogs.SelectParameters.Add("paginado", TypeCode.Boolean, "true"); odsLogs.DataBind(); _dgvLogs.Visible = true; } catch (Exception err) { ApplicationWEB._GravaErro(err); _lblMessage.Text = UtilBO.GetErroMessage(String.Format("Erro ao tentar selecionar a data {0}.", e.CommandArgument), UtilBO.TipoMensagem.Alerta); } } else if (e.CommandName.Equals("Download")) { try { int sis_id = Convert.ToInt32(UCComboSistema1._Combo.SelectedValue); DateTime data = Convert.ToDateTime(e.CommandArgument); string fileName = String.Format("Log_{0}_{1}_{2}.txt" , data.Year , data.Month , data.Day); List <LOG_Erros> lt = LOG_ErrosBO.GetSelectBy_dia2(sis_id, data, _txtUsuario.Text, false, 1, 1); _Exportar_ArquivoTXT(lt, fileName); } catch (ThreadAbortException) { } catch (Exception err) { ApplicationWEB._GravaErro(err); _lblMessage.Text = UtilBO.GetErroMessage(String.Format("Erro ao tentar baixar o log de erros da data {0}.", e.CommandArgument), UtilBO.TipoMensagem.Alerta); } } }
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> /// 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 { } }