Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <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 { }
        }