/// <summary> /// invoke the method will save the application log to database. /// <code> /// App_Log_SQL appLogSql = new App_Log_SQL(); /// appLogSql.CreatedOn = System.DateTime.Now; /// appLogSql.SaveLog(Common.RegistryKeyValue); /// </code> /// </summary> /// <param name="registryKeyValue">the registry key value of data connection string.</param> public ReturnValue SaveLog() { ReturnValue _result = new ReturnValue(); this.CreatedOn = System.DateTime.Now; if (Notes != null) { if (Notes.IndexOf("Invalid viewstate") > -1 || Notes.IndexOf("Path 'OPTIONS' is forbidden") > -1 || Notes.IndexOf("Path 'PUT' is forbidden") > -1 || Notes.IndexOf("www.scanalert.com/bot.jsp") > -1 || Notes.IndexOf("Path 'PROPFIND' is forbidden") > -1 || Notes.IndexOf("Failed to load viewstate") > -1 || Notes == "0" || Notes.IndexOf("does not exist.---- at System.Web.UI.Util.CheckVirtualFileExists") > -1 || this.URL.IndexOf("style.aspx") > -1 || this.URL.IndexOf("ScriptResource.axd") > -1 || this.URL.IndexOf("WebResource.axd") > -1 ) { return(_result); } } try { Gateway gateway = new Gateway(this); _result = gateway.Save(); this.ID = _result.IdentityId; } catch { } LogEmail.Send(this); return(_result); //if (System.Configuration.ConfigurationManager.AppSettings["ErrorPage"] != null) //{ // try // { // HttpContext.Current.Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["ErrorPage"].ToString()); // } // catch (Exception ex) // { // string aa = ex.Message; // } //} }
/// <summary> /// save App_Log_SQL to database for transaction. /// </summary> /// <param name="returnvalue">the result of WComm.Framework.ReturnValue.</param> /// <param name="dal">The DataFactory instance of transaction.</param> protected void SaveLog(ReturnValue returnvalue, string TableName, string SQLType) { SaveLogType saveLogType = App_Log_SQL.getSaveLogConfig(); switch (saveLogType) { case SaveLogType.None: { break; } case SaveLogType.Always: { App_Log_SQL appLogSQL = new App_Log_SQL(); appLogSQL.DataConnectProviders = this.DataConnectProviders; appLogSQL.CreatedOn = System.DateTime.Now; appLogSQL.SQLText = returnvalue.SQLText; appLogSQL.Success = returnvalue.Success; appLogSQL.Notes = returnvalue.ErrMessage; appLogSQL.TableName = TableName; appLogSQL.SQLType = SQLType; try { if (WComm.Utilities.isInteger(WComm.Utilities.CurrentProgramId.ToString())) { appLogSQL.ProgramId = WComm.Utilities.CurrentProgramId; } if (WComm.Utilities.isInteger(WComm.Utilities.CurrentUserId.ToString())) { appLogSQL.UserId = WComm.Utilities.CurrentUserId; } } catch { } appLogSQL.Save(); break; } case SaveLogType.Error: { if (returnvalue.Success == false) { App_Log_SQL appLogSQL = new App_Log_SQL(); appLogSQL.DataConnectProviders = this.DataConnectProviders; appLogSQL.CreatedOn = System.DateTime.Now; appLogSQL.SQLText = returnvalue.SQLText; appLogSQL.Success = returnvalue.Success; appLogSQL.Notes = returnvalue.ErrMessage; appLogSQL.TableName = TableName; appLogSQL.SQLType = SQLType; try { if (WComm.Utilities.isInteger(WComm.Utilities.CurrentProgramId.ToString())) { appLogSQL.ProgramId = WComm.Utilities.CurrentProgramId; } if (WComm.Utilities.isInteger(WComm.Utilities.CurrentUserId.ToString())) { appLogSQL.UserId = WComm.Utilities.CurrentUserId; } } catch { } if (returnvalue.ErrMessage != null && returnvalue.ErrMessage.ToUpper().IndexOf("TIMEOUT") > 0) { appLogSQL.Type = "TIMEOUT"; } if (returnvalue.ErrMessage != null && returnvalue.ErrMessage.ToUpper().IndexOf("DEADLOCKED") > 0) { appLogSQL.Type = "DEADLOCKED"; } using (TransactionScope ts_appLogSQL = new TransactionScope(TransactionScopeOption.Suppress)) { appLogSQL.Save(); ts_appLogSQL.Complete(); } LogEmail.Send(appLogSQL); } break; } } }
private ReturnValue underSave(Gateway gateway) { ReturnValue result = Validate(); if (!result.Success) { return(result); } result = gateway.Save(); #region App_Log_SQL if (gateway.TableName.ToUpper() != "App_Log_SQL".ToUpper()) { if (result.Success == false) { SaveLog(result, gateway.TableName, "Save"); } else { result = this.SaveTraceLog(result, gateway.TableName, "Save", gateway.Trans); } } else { if (result.Success == false) { string path = "App_Log_Falied_Result.log"; string _message = "Date:" + System.DateTime.Now.ToString() + "\r\n" + "Table Name:" + gateway.TableName + "\r\n" + "SQL:" + result.SQLText + "\r\n" + "Result:" + result.ErrMessage + "\r\n\r\n"; if (System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] == null) { try { path = HttpContext.Current.Request.PhysicalApplicationPath + path; } catch { } } else { path = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] + path; } try { if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine(_message); } } else { using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(_message); } } } catch { } LogEmail.Send(this as App_Log_SQL); } } #endregion return(result); }