Example #1
0
        async Task BulkInsert(IEnumerable <LogEvent> events, MySqlConnection connection)
        {
            var eventData   = events.Select(i => Core.GetColumnsAndValues(i)).ToList();
            var commandText = Core.GetBulkInsertStatement(eventData);

            using (var cmd = new MySqlCommand(commandText, connection))
            {
                var i = 0;
                eventData.ForEach(columnValues => {
                    columnValues.Where(x => x.Value != null).ToList().ForEach(x => cmd.Parameters.AddWithValue($"{x.Key}{i}", x.Value));
                    i++;
                });
                await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
        }
Example #2
0
        public void Emit(LogEvent logEvent)
        {
            try
            {
                using (var conn = new MySqlConnection(_connectionString))
                {
                    conn.Open();

                    var columnValues = _core.GetColumnsAndValues(logEvent).ToList();
                    var commandText  = _core.GetInsertStatement(columnValues);

                    using (var cmd = new MySqlCommand(commandText, conn))
                    {
                        foreach (var columnValue in columnValues)
                        {
                            if (columnValue.Value != null)
                            {
                                cmd.Parameters.AddWithValue(columnValue.Key, columnValue.Value);
                            }
                        }

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Unable to write log event to the database due to following error: {1}", ex.Message);
                throw;
            }
        }
        private async Task BulkInsert(IEnumerable <LogEvent> events, MySqlConnection connection)
        {
            var eventData   = events.Select(i => _core.GetColumnsAndValues(i)).ToList();
            var commandText = _core.GetBulkInsertStatement(eventData);

            using (var cmd = new MySqlCommand(commandText, connection))
            {
                int i = 0;
                foreach (var columnValues in eventData)
                {
                    foreach (var columnValue in columnValues)
                    {
                        if (columnValue.Value != null)
                        {
                            cmd.Parameters.AddWithValue($"{columnValue.Key}{i}", columnValue.Value);
                        }
                    }
                    i++;
                }
                await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
        }
        public void Emit(LogEvent logEvent)
        {
            try
            {
                using var conn = new MySqlConnection(ConnectionString);
                conn.Open();

                var columnValues = Core.GetColumnsAndValues(logEvent).ToList();
                using var cmd = new MySqlCommand(Core.GetInsertStatement(columnValues), conn);
                columnValues.Where(x => x.Value != null).ToList().ForEach(x => cmd.Parameters.AddWithValue(x.Key, x.Value));
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Unable to write log event to the database due to following error: {1}", ex.Message);
                throw;
            }
        }