/// <summary>Saves the exception to database.</summary> /// <param name="transaction">The transaction.</param> /// <param name="exception">The exception.</param> /// <param name="parentEventId">The parent event id.</param> /// <param name="parentExceptionId">The parent exception id.</param> /// <returns>The database's primary key of the saved exception.</returns> /// <exception cref="ArgumentNullException">Thrown when either <paramref name="transaction"/> or /// <paramref name="exception"/> are null (Nothing in VB) references.</exception> protected virtual int SaveExceptionToDatabase(SqlTransaction transaction, Exception exception, int parentEventId, int?parentExceptionId) { if (exception == null) { throw new ArgumentNullException("exception"); } if (transaction == null) { throw new ArgumentNullException("transaction"); } using (var command = new SqlCommand(AddExceptionProcedure, transaction.Connection, transaction)) { command.CommandType = CommandType.StoredProcedure; SqlLoggingHelper.AddParameter(command, "EventId", SqlDbType.Int, parentEventId); SqlLoggingHelper.AddParameter(command, "ParentExceptionId", SqlDbType.Int, parentExceptionId); SqlLoggingHelper.AddParameter(command, "ExceptionType", SqlDbType.NVarChar, exception.GetType().Name); SqlLoggingHelper.AddParameter(command, "Message", SqlDbType.NText, exception.Message); SqlLoggingHelper.AddParameter(command, "StackTrace", SqlDbType.NText, exception.StackTrace); object exceptionId = command.ExecuteScalar(); if (!(exceptionId is int)) { throw new InvalidOperationException(SR.StoredProcedureReturnedInvalidValue( AddExceptionProcedure, exceptionId, typeof(int))); } return((int)exceptionId); } }
/// <summary>Saves the event to database.</summary> /// <param name="transaction">The transaction.</param> /// <param name="severity">The severity of the event.</param> /// <param name="message">The message.</param> /// <param name="source">The source.</param> /// <returns>The database's primary key of the saved event.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="transaction"/> is a null /// (Nothing in VB) reference.</exception> protected virtual int SaveEventToDatabase(SqlTransaction transaction, LoggingEventType severity, string message, string source) { if (transaction == null) { throw new ArgumentNullException("transaction"); } using (var command = new SqlCommand(AddEventProcedure, transaction.Connection, transaction)) { command.CommandType = CommandType.StoredProcedure; SqlLoggingHelper.AddParameter(command, "EventTypeId", SqlDbType.Int, (int)severity); SqlLoggingHelper.AddParameter(command, "Message", SqlDbType.NText, message); SqlLoggingHelper.AddParameter(command, "Source", SqlDbType.NText, source); object eventId = command.ExecuteScalar(); if (!(eventId is int)) { throw new InvalidOperationException(SR.StoredProcedureReturnedInvalidValue( AddEventProcedure, eventId, typeof(int))); } return((int)eventId); } }