Exemplo n.º 1
0
        string IErrorLogManager.LogExceptionToDatabase(Exception ex, string FormData = "", string QueryData = "", string RouteData = "")
        {
            ErrorLog obj_errorlog = null;
            String ex_text = String.Empty;
            String ex_message = ex.Message;
            try
            {
                obj_errorlog = new ErrorLog();
                obj_errorlog.Message = ex.Message;
                obj_errorlog.StackTrace = ex.StackTrace;
                obj_errorlog.InnerException = ex.InnerException == null ? "" : ex.InnerException.Message;
                obj_errorlog.LoggedInDetails = "";
                obj_errorlog.LoggedAt = DateTime.Now;

                obj_errorlog.FormData = FormData;
                obj_errorlog.QueryData = QueryData;
                obj_errorlog.RouteData = RouteData;
                //=======================================================================

                ex_text = JsonConvert.SerializeObject(obj_errorlog);
                Context.ErrorLogs.Add(obj_errorlog);
                SaveChanges();
                return obj_errorlog.ErrorLogID.ToString();

            }
            catch (Exception)
            {
                System.IO.StreamWriter sw = null;
                if (!File.Exists(HostingEnvironment.MapPath("~/ErrorLog.txt")))
                    File.Create(HostingEnvironment.MapPath("~/ErrorLog.txt"));
                sw = new StreamWriter(HostingEnvironment.MapPath("~/ErrorLog.txt"), true);
                sw.WriteLine(ex_message);
                sw.WriteLine("/");
                sw.WriteLine(ex); sw.WriteLine(""); sw.WriteLine("");
                sw.Close();
                return "0";
            }
        }
Exemplo n.º 2
0
 string IHomeManager.LogExceptionToDatabase(Exception ex)
 {
     ErrorLog errorObj = new ErrorLog();
     errorObj.Message = ex.Message;
     errorObj.StackTrace = ex.StackTrace;
     errorObj.InnerException = ex.InnerException == null ? "" : ex.InnerException.Message;
     errorObj.LoggedInDetails = "";
     errorObj.LoggedAt = DateTime.UtcNow;
     Context.ErrorLogs.Add(errorObj);
     Context.SaveChanges();
     return errorObj.ErrorLogID.ToString();
 }