private ErrorEvent GetErrorEventFromRecord(NpgsqlDataReader reader)
 {
     var errorEvent = new ErrorEvent
     {
         Command = (CommandType)reader.GetValue(8),
         StockSymbol = (reader.IsDBNull(9)) ? null : reader.GetString(9),
         Funds = (reader.IsDBNull(10)) ? null : (decimal?) reader.GetDecimal(10),
         FileName = (reader.IsDBNull(11)) ? null : reader.GetString(11),
         ErrorMessage = (reader.IsDBNull(12)) ? null : reader.GetString(12)
     };
     FillBaseEventPropertiesFromRecord(errorEvent, reader);
     return errorEvent;
 }
        public void LogErrorEvent(ErrorEvent errorEvent)
        {
            using (var command = new NpgsqlCommand("log_error_event"))
            {
                Log.DebugFormat("Inserting error event {0} into databse...", errorEvent.Id);

                command.CommandType = System.Data.CommandType.StoredProcedure;

                AddCommonEventPropertyParametersToCommand(command, errorEvent);

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Enum,
                    Value = errorEvent.Command
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Char,
                    Value = ((object) errorEvent.StockSymbol) ?? DBNull.Value
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Money,
                    Value = ((object) errorEvent.Funds) ?? DBNull.Value
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Varchar,
                    Value = ((object) errorEvent.ErrorMessage) ?? DBNull.Value
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Varchar,
                    Value = ((object) errorEvent.FileName) ?? DBNull.Value
                });

                int id = ExecuteInsertCommand(command);

                Log.DebugFormat(CultureInfo.InvariantCulture,
                    "Successfully inserted error event {0} (database id = {1}).", errorEvent.Id, id);
            }
        }