/// <summary> /// Add user comments to an existing error. This is added in the base error node as an attribute userComments /// </summary> public override void AddUserComments(string id, string userComments) { if (id == null) { throw new ArgumentNullException("id"); } if (id.Length == 0) { throw new ArgumentException(null, "id"); } Guid errorGuid; try { errorGuid = new Guid(id); } catch (FormatException e) { throw new ArgumentException(e.Message, "id", e); } var someError = GetError(id); someError.Error.UserComments = userComments; using (var connection = new SqlConnection(ConnectionString)) using (var command = Commands.UpdateErrorXml(errorGuid, ErrorXml.EncodeString(someError.Error))) { command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); } }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); Guid id = Guid.NewGuid(); using (OracleConnection connection = new OracleConnection(this.ConnectionString)) using (OracleCommand command = connection.CreateCommand()) { connection.Open(); using (OracleTransaction transaction = connection.BeginTransaction()) { // because we are storing the XML data in a NClob, we need to jump through a few hoops!! // so first we've got to operate within a transaction command.Transaction = transaction; // then we need to create a temporary lob on the database server command.CommandText = "declare xx nclob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;"; command.CommandType = CommandType.Text; OracleParameterCollection parameters = command.Parameters; parameters.Add("tempblob", OracleType.NClob).Direction = ParameterDirection.Output; command.ExecuteNonQuery(); // now we can get a handle to the NClob OracleLob xmlLob = (OracleLob)parameters[0].Value; // create a temporary buffer in which to store the XML byte[] tempbuff = Encoding.Unicode.GetBytes(errorXml); // and finally we can write to it! xmlLob.BeginBatch(OracleLobOpenMode.ReadWrite); xmlLob.Write(tempbuff, 0, tempbuff.Length); xmlLob.EndBatch(); command.CommandText = SchemaOwner + "pkg_elmah$log_error.LogError"; command.CommandType = CommandType.StoredProcedure; parameters.Clear(); parameters.Add("v_ErrorId", OracleType.NVarChar, 32).Value = id.ToString("N"); parameters.Add("v_Application", OracleType.NVarChar, _maxAppNameLength).Value = ApplicationName; parameters.Add("v_Host", OracleType.NVarChar, 30).Value = error.HostName; parameters.Add("v_Type", OracleType.NVarChar, 100).Value = error.Type; parameters.Add("v_Source", OracleType.NVarChar, 60).Value = error.Source; parameters.Add("v_Message", OracleType.NVarChar, 500).Value = error.Message; parameters.Add("v_User", OracleType.NVarChar, 50).Value = error.User; parameters.Add("v_AllXml", OracleType.NClob).Value = xmlLob; parameters.Add("v_StatusCode", OracleType.Int32).Value = error.StatusCode; parameters.Add("v_TimeUtc", OracleType.DateTime).Value = error.Time.ToUniversalTime(); command.ExecuteNonQuery(); transaction.Commit(); } return(id.ToString()); } }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); using (OleDbConnection connection = new OleDbConnection(this.ConnectionString)) using (OleDbCommand command = connection.CreateCommand()) { connection.Open(); command.CommandType = CommandType.Text; command.CommandText = @"INSERT INTO ELMAH_Error (Application, Host, Type, Source, Message, UserName, StatusCode, TimeUtc, AllXml) VALUES (@Application, @Host, @Type, @Source, @Message, @UserName, @StatusCode, @TimeUtc, @AllXml)"; command.CommandType = CommandType.Text; OleDbParameterCollection parameters = command.Parameters; parameters.Add("@Application", OleDbType.VarChar, _maxAppNameLength).Value = ApplicationName; parameters.Add("@Host", OleDbType.VarChar, 30).Value = error.HostName; parameters.Add("@Type", OleDbType.VarChar, 100).Value = error.Type; parameters.Add("@Source", OleDbType.VarChar, 60).Value = error.Source; parameters.Add("@Message", OleDbType.LongVarChar, error.Message.Length).Value = error.Message; parameters.Add("@User", OleDbType.VarChar, 50).Value = error.User; parameters.Add("@StatusCode", OleDbType.Integer).Value = error.StatusCode; parameters.Add("@TimeUtc", OleDbType.Date).Value = error.Time.ToUniversalTime(); parameters.Add("@AllXml", OleDbType.LongVarChar, errorXml.Length).Value = errorXml; command.ExecuteNonQuery(); using (OleDbCommand identityCommand = connection.CreateCommand()) { identityCommand.CommandType = CommandType.Text; identityCommand.CommandText = "SELECT @@IDENTITY"; return(Convert.ToString(identityCommand.ExecuteScalar(), CultureInfo.InvariantCulture)); } } }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); Guid id = Guid.NewGuid(); const string query = @" INSERT INTO ELMAH_Error ( [ErrorId], [Application], [Host], [Type], [Source], [Message], [User], [StatusCode], [TimeUtc], [AllXml] ) VALUES ( @ErrorId, @Application, @Host, @Type, @Source, @Message, @User, @StatusCode, @TimeUtc, @AllXml);"; using (SqlCeConnection connection = new SqlCeConnection(ConnectionString)) { using (SqlCeCommand command = new SqlCeCommand(query, connection)) { SqlCeParameterCollection parameters = command.Parameters; parameters.Add("@ErrorId", SqlDbType.UniqueIdentifier).Value = id; parameters.Add("@Application", SqlDbType.NVarChar, 60).Value = ApplicationName; parameters.Add("@Host", SqlDbType.NVarChar, 30).Value = error.HostName; parameters.Add("@Type", SqlDbType.NVarChar, 100).Value = error.Type; parameters.Add("@Source", SqlDbType.NVarChar, 60).Value = error.Source; parameters.Add("@Message", SqlDbType.NVarChar, 500).Value = error.Message; parameters.Add("@User", SqlDbType.NVarChar, 50).Value = error.User; parameters.Add("@StatusCode", SqlDbType.Int).Value = error.StatusCode; parameters.Add("@TimeUtc", SqlDbType.DateTime).Value = error.Time.ToUniversalTime(); parameters.Add("@AllXml", SqlDbType.NText).Value = errorXml; command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); return(id.ToString()); } } }
public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); Guid id = Guid.NewGuid(); using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString)) using (NpgsqlCommand command = Commands.LogError(id, this.ApplicationName, error.HostName, error.Type, error.Source, error.Message, error.User, error.StatusCode, error.Time, errorXml)) { command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); return(id.ToString()); } }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); const string query = @" INSERT INTO Error ( Application, Host, Type, Source, Message, User, StatusCode, TimeUtc, AllXml) VALUES ( @Application, @Host, @Type, @Source, @Message, @User, @StatusCode, @TimeUtc, @AllXml); SELECT last_insert_rowid();"; using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) using (SQLiteCommand command = new SQLiteCommand(query, connection)) { SQLiteParameterCollection parameters = command.Parameters; parameters.Add("@Application", DbType.String, 60).Value = ApplicationName; parameters.Add("@Host", DbType.String, 30).Value = error.HostName; parameters.Add("@Type", DbType.String, 100).Value = error.Type; parameters.Add("@Source", DbType.String, 60).Value = error.Source; parameters.Add("@Message", DbType.String, 500).Value = error.Message; parameters.Add("@User", DbType.String, 50).Value = error.User; parameters.Add("@StatusCode", DbType.Int64).Value = error.StatusCode; parameters.Add("@TimeUtc", DbType.DateTime).Value = error.Time.ToUniversalTime(); parameters.Add("@AllXml", DbType.String).Value = errorXml; connection.Open(); return(Convert.ToInt64(command.ExecuteScalar()).ToString(CultureInfo.InvariantCulture)); } }
public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } var errorXml = ErrorXml.EncodeString(error); var errorDoc = new ErrorDocument { ApplicationName = ApplicationName, Error = error, ErrorXml = errorXml }; using (var session = _documentStore.OpenSession()) { session.Store(errorDoc); session.SaveChanges(); } return(errorDoc.Id); }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); using (VistaDBConnection connection = new VistaDBConnection(this.ConnectionString)) using (VistaDBCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = @"INSERT INTO ELMAH_Error (Application, Host, Type, Source, Message, [User], AllXml, StatusCode, TimeUtc) VALUES (@Application, @Host, @Type, @Source, @Message, @User, @AllXml, @StatusCode, @TimeUtc); SELECT @@IDENTITY"; command.CommandType = CommandType.Text; VistaDBParameterCollection parameters = command.Parameters; parameters.Add("@Application", VistaDBType.NVarChar, _maxAppNameLength).Value = ApplicationName; parameters.Add("@Host", VistaDBType.NVarChar, 30).Value = error.HostName; parameters.Add("@Type", VistaDBType.NVarChar, 100).Value = error.Type; parameters.Add("@Source", VistaDBType.NVarChar, 60).Value = error.Source; parameters.Add("@Message", VistaDBType.NVarChar, 500).Value = error.Message; parameters.Add("@User", VistaDBType.NVarChar, 50).Value = error.User; parameters.Add("@AllXml", VistaDBType.NText).Value = errorXml; parameters.Add("@StatusCode", VistaDBType.Int).Value = error.StatusCode; parameters.Add("@TimeUtc", VistaDBType.DateTime).Value = error.Time.ToUniversalTime(); return(Convert.ToString(command.ExecuteScalar(), CultureInfo.InvariantCulture)); } }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } var errorXml = ErrorXml.EncodeString(error); var id = Guid.NewGuid(); using (var connection = CreateOpenConnection()) using (var command = connection.CreateCommand()) using (var transaction = connection.BeginTransaction()) { // because we are storing the XML data in a NClob, we need to jump through a few hoops!! // so first we've got to operate within a transaction command.Transaction = transaction; // then we need to create a temporary lob on the database server command.CommandText = "declare xx nclob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;"; command.CommandType = CommandType.Text; var parameters = command.Parameters; AddProviderSpecificTypeParameter(command, "tempblob", ThisProviderInfo.ClobDbType).Direction = ParameterDirection.Output; command.ExecuteNonQuery(); object xmlValue; if (parameters[0].Value is string) { xmlValue = errorXml; } else { // now we can get a handle to the NClob // TODO Review where Stream needs disposing var stream = (Stream)parameters[0].Value; // create a temporary buffer in which to store the XML var bytes = Encoding.Unicode.GetBytes(errorXml); // and finally we can write to it! stream.Write(bytes, 0, bytes.Length); xmlValue = stream; } command.CommandText = SchemaOwner + "pkg_elmah$log_error.LogError"; command.CommandType = CommandType.StoredProcedure; parameters.Clear(); var addParameter = command.ParameterAdder(); addParameter("v_ErrorId", DbType.String, id.ToString("N")); addParameter("v_Application", DbType.String, ApplicationName); addParameter("v_Host", DbType.String, error.HostName); addParameter("v_Type", DbType.String, error.Type); addParameter("v_Source", DbType.String, error.Source); addParameter("v_Message", DbType.String, error.Message); addParameter("v_User", DbType.String, error.User); AddProviderSpecificTypeParameter(command, "v_AllXml", ThisProviderInfo.ClobDbType).Value = xmlValue; addParameter("v_StatusCode", DbType.Int32, error.StatusCode); addParameter("v_TimeUtc", DbType.DateTime, error.Time.ToUniversalTime()); command.ExecuteNonQuery(); transaction.Commit(); return(id.ToString()); } }