public override void OnException(HttpActionExecutedContext actionExecutedContext) { _errorLogManager = new ErrorLogManager(); var ex = actionExecutedContext.Exception; try { //Log exception in database _errorLogManager.LogExceptionToDatabase(ex); } catch (Exception) { System.IO.StreamWriter sw = null; try { sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/ErrorLog.txt"), true); sw.WriteLine(ex.Message); sw.WriteLine("http://jsonformat.com/"); sw.WriteLine(ex); sw.WriteLine(""); sw.WriteLine(""); } catch { } finally { sw.Close(); } } _errorLogManager.LogExceptionToDatabase(ex); System.IO.StreamWriter sw1 = null; sw1 = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/ErrorLog.txt"), true); sw1.WriteLine(ex.Message); sw1.WriteLine("http://jsonformat.com/"); sw1.WriteLine(ex); sw1.WriteLine(""); sw1.WriteLine(""); sw1.Close(); actionExecutedContext.Response = new JsonContent("An Unexpected Error Has Occured!", ActionStatus.Error).ConvertToHttpResponseOK(); }
/// <summary> /// log exception to database /// </summary> /// <param name="ex"></param> /// <returns></returns> public String LogExceptionToDatabase(Exception ex) { try { //Log exception in database var result = _errorLogManager.LogExceptionToDatabase(ex); //Log exception in file LogExceptionToFile("", ex.Message); } catch (Exception) { LogExceptionToFile("", ex.Message); return("0"); } return(null); }