public int LogError(string message, ErrorType type, Exception e) { var requestId = HttpContext.Current.Items[Keys.REQUEST_ID_KEY] as int?; var errorId = _LoggerDao.LogError(requestId, message, type, e); return errorId; }
public int LogErrorInternal(string message, ErrorType type, Exception e, HttpContextLoggerInfo wrapper) { var connection = new SqlConnection(ConnectionString); var cmd = new SqlCommand("dbo.LogError", connection) { CommandType = CommandType.StoredProcedure }; var requestIdParameter = new SqlParameter("RequestId", SqlDbType.BigInt) { Direction = ParameterDirection.InputOutput }; cmd.Parameters.Add(requestIdParameter); if (wrapper == null) { requestIdParameter.Value = null; } else { SetWebEnabledParameters(cmd, wrapper); requestIdParameter.Value = wrapper.Items[REQUEST_ID_CONTEXT_KEY]; } SetStandAloneErrorParameters(message, type, e, cmd); ExecuteCommand(connection, cmd); RequestId = Convert.ToInt32(cmd.Parameters["RequestId"].Value); if (wrapper != null && wrapper.Items[REQUEST_ID_CONTEXT_KEY] == null) { wrapper.Items[REQUEST_ID_CONTEXT_KEY] = RequestId; } return Convert.ToInt32(cmd.Parameters["ErrorId"].Value); }
public Int32 LogError(Int32? requestId, string message, ErrorType type, Exception e) { var connection = new SqlConnection(ConnectionString); var cmd = new SqlCommand("dbo.LogError2", connection) {CommandType = System.Data.CommandType.StoredProcedure}; if (requestId != null) cmd.Parameters.Add(new SqlParameter("RequestId", System.Data.SqlDbType.BigInt)).Value = requestId; //cmd.Parameters.Add(new SqlParameter("AppId", System.Data.SqlDbType.NChar)).Value = this.App.Key; cmd.Parameters.Add(new SqlParameter("ErrorTypeId", System.Data.SqlDbType.NChar)).Value = type.Key; cmd.Parameters.Add(new SqlParameter("ErrorText", System.Data.SqlDbType.NVarChar)).Value = message; var erroridparam = new SqlParameter("ErrorId", System.Data.SqlDbType.BigInt) {Direction = System.Data.ParameterDirection.Output}; cmd.Parameters.Add(erroridparam); if (e != null) { cmd.Parameters.Add(new SqlParameter("StackTraceText", System.Data.SqlDbType.NVarChar)).Value = e.Message + "\n" + e.StackTrace; } ExecuteCommand(connection, cmd); var errorId = Convert.ToInt32(erroridparam.Value); while (e.InnerException != null) { e = e.InnerException; const string insertExtraStackTraceSql = "insert into dbo.stacktrace (errorid, stacktracetext) values (@ErrorId, @StackTraceText)"; var insertExtraStackTrace = new SqlCommand(insertExtraStackTraceSql, connection) {CommandType = System.Data.CommandType.Text}; insertExtraStackTrace.Parameters.Add(new SqlParameter("ErrorId", System.Data.SqlDbType.BigInt)).Value = errorId; insertExtraStackTrace.Parameters.Add(new SqlParameter("StackTraceText", System.Data.SqlDbType.NVarChar)).Value = e.Message + "\n" + e.StackTrace; ExecuteCommand(connection, insertExtraStackTrace); } return errorId; }
public int LogError(string message, ErrorType type, Exception e) { var wrapper = GetLoggerInfo(); return _LoggerDao.LogErrorInternal(message, type, e, wrapper); }
private void SetStandAloneErrorParameters(string message, ErrorType type, Exception e, SqlCommand cmd) { cmd.Parameters.Add(new SqlParameter("AppId", SqlDbType.NChar)).Value = App.Key; cmd.Parameters.Add(new SqlParameter("ErrorTypeId", SqlDbType.NChar)).Value = type.Key; cmd.Parameters.Add(new SqlParameter("ErrorText", SqlDbType.NVarChar)).Value = message; var stackTraceText = BuildFullStackTraceText(e); if (e != null) { cmd.Parameters.Add(new SqlParameter("StackTraceText", SqlDbType.NVarChar)).Value = BuildFullStackTraceText(e); } var errorIdSqlParameter = new SqlParameter("ErrorId", SqlDbType.BigInt) { Direction = ParameterDirection.Output }; cmd.Parameters.Add(errorIdSqlParameter); }