public void LogException(Exception ex)
{
LogException(ex, null);
}
public void LogExceptionx(Exception ex, SqlCommand objBadCmd)
{
int id = 0;
if (this._WritingErrorLog == true)
{
// don't want to get in an infinite loop.
return;
}
else
{
this._WritingErrorLog = true;
}
try
{
SqlCommand objCmd = this.GetNewCmd("dbo.insertException");
string message = "";
// Get the userId of the user that got the error.
if (System.Web.HttpContext.Current.Request.Cookies["UID"] != null)
message = System.Web.HttpContext.Current.Request.Cookies["UID"].Value + "|";
// Add the command that gave the error.
if (objBadCmd != null && !string.IsNullOrEmpty(objBadCmd.CommandText))
message += objBadCmd.CommandText + "|";
message += ex.ToString();
if (message.Length > 8000)
message = message.Substring(0, 7999);
objCmd.Parameters.Add("@Message", SqlDbType.VarChar, 8000).Value = message;
objCmd.Parameters.Add("@StackTrace", SqlDbType.VarChar, 8000).Value =
((ex.StackTrace == null) ? "no stack trace." : ex.StackTrace);
//insert the exception and get the new ID.
id = this.ExecuteScalarInt(objCmd);
if (id > 0 && objBadCmd != null)
insertExceptionCmd(id, objBadCmd);
}
catch (Exception ExLogException)
{
this.LogExceptionToFile(ex);
this.LogExceptionToFile(ExLogException);
}
this._WritingErrorLog = false;
}