Esempio n. 1
0
        public void SaveLog(LogEntry logEntry)
        {
            DbConnection connection = DbConnectionProvider.GetDbConnection(ActiveAppEnvironment.GetConfig(AppEnvironment.KeyValues.Data.LogDbConnectionstring, defaultValueOnNotFoundProvider: () => ActiveAppEnvironment.GetConfig <string>("AppConnectionstring")), rollbackOnScopeStatusFailure: false);

            using (DbCommand command = connection.CreateCommand())
            {
                command.Transaction = DbConnectionProvider.GetDbTransaction(connection);

                command.CommandText = @"INSERT INTO [dbo].[Logs] ([Contents]) VALUES (@contents)";

                command.AddParameterWithValue("@contents", Formatter.Serialize(logEntry.ToDictionary()));

                command.ExecuteNonQuery();
            }
        }
        public virtual async Task SaveLogAsync(LogEntry logEntry)
        {
            using (SqlConnection connection = new SqlConnection(ActiveAppEnvironment.GetConfig <string>("AppConnectionstring")))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = @"INSERT INTO [dbo].[Logs] ([Contents]) VALUES (@contents)";

                    command.Parameters.AddWithValue("@contents", Formatter.Serialize(logEntry));

                    await connection.OpenAsync().ConfigureAwait(false);

                    await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                }
            }
        }
Esempio n. 3
0
        public void SaveLog(LogEntry logEntry)
        {
            using (SqlConnection connection = new SqlConnection(ActiveAppEnvironment.GetConfig("LogDbConnectionstring", defaultValueOnNotFoundProvider: () => ActiveAppEnvironment.GetConfig <string>("AppConnectionstring"))))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = @"INSERT INTO [dbo].[Logs] ([Contents]) VALUES (@contents)";

                    command.Parameters.AddWithValue("@contents", Formatter.Serialize(logEntry.ToDictionary()));

                    connection.Open();

                    command.ExecuteNonQuery();
                }
            }
        }
        public virtual async Task SaveLogAsync(LogEntry logEntry)
        {
            if (logEntry == null)
            {
                throw new ArgumentNullException(nameof(logEntry));
            }

            DbConnection connection = await DbConnectionProvider.GetDbConnectionAsync(ActiveAppEnvironment.GetConfig(AppEnvironment.KeyValues.Data.LogDbConnectionstring, defaultValueOnNotFoundProvider : () => ActiveAppEnvironment.GetConfig <string>("AppConnectionstring")) ?? throw new InvalidOperationException($"{nameof(AppEnvironment.KeyValues.Data.LogDbConnectionstring)} is null."), rollbackOnScopeStatusFailure : false, cancellationToken : CancellationToken.None).ConfigureAwait(false);

            await using (DbCommand command = connection.CreateCommand())
            {
                command.Transaction = DbConnectionProvider.GetDbTransaction(connection);

                command.CommandText = @"INSERT INTO [dbo].[Logs] ([Contents]) VALUES (@contents)";

                command.AddParameterWithValue("@contents", ContentFormatter.Serialize(logEntry.ToDictionary()));

                await command.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
        }