From 729c36ff6797df6be081e78fb609c43af205a1d4 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 20 Jul 2018 14:22:23 -0400 Subject: [PATCH] Fix up some things with efc logging --- .../Models/DatabaseContext.cs | 18 +----------------- .../MySqlDesignTimeDbContextFactory.cs | 3 +-- .../SqlServerDesignTimeDbContextFactory.cs | 3 +-- .../SqliteDesignTimeDbContextFactory.cs | 3 +-- .../Models/MySqlDatabaseContext.cs | 4 +--- .../Models/SqlServerDatabaseContext.cs | 4 +--- .../Models/SqliteDatabaseContext.cs | 4 +--- src/Tgstation.Server.Host/appsettings.json | 2 +- 8 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/Tgstation.Server.Host/Models/DatabaseContext.cs b/src/Tgstation.Server.Host/Models/DatabaseContext.cs index 1aa4170164..e92934f70e 100644 --- a/src/Tgstation.Server.Host/Models/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/DatabaseContext.cs @@ -1,10 +1,7 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; -#if !DEBUG using System.Linq; -#endif using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Configuration; @@ -83,10 +80,6 @@ namespace Tgstation.Server.Host.Models /// readonly DatabaseConfiguration databaseConfiguration; /// - /// The for the - /// - readonly ILoggerFactory loggerFactory; - /// /// The for the /// readonly IDatabaseSeeder databaseSeeder; @@ -96,12 +89,10 @@ namespace Tgstation.Server.Host.Models /// /// The for the /// The containing the value of - /// The value of /// The value of - public DatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfigurationOptions, ILoggerFactory loggerFactory, IDatabaseSeeder databaseSeeder) : base(dbContextOptions) + public DatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfigurationOptions, IDatabaseSeeder databaseSeeder) : base(dbContextOptions) { databaseConfiguration = databaseConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions)); - this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.databaseSeeder = databaseSeeder ?? throw new ArgumentNullException(nameof(databaseSeeder)); } @@ -128,8 +119,6 @@ namespace Tgstation.Server.Host.Models protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); - - optionsBuilder.UseLoggerFactory(loggerFactory); } /// @@ -147,14 +136,9 @@ namespace Tgstation.Server.Host.Models /// public async Task Initialize(CancellationToken cancellationToken) { -#if DEBUG - await Database.EnsureCreatedAsync().ConfigureAwait(false); - var wasEmpty = (await Users.CountAsync().ConfigureAwait(false)) == 0; -#else var migrations = await Database.GetAppliedMigrationsAsync().ConfigureAwait(false); var wasEmpty = !migrations.Any(); await Database.MigrateAsync(cancellationToken).ConfigureAwait(false); -#endif if (wasEmpty) await databaseSeeder.SeedDatabase(this, cancellationToken).ConfigureAwait(false); } diff --git a/src/Tgstation.Server.Host/Models/Migrations/MySqlDesignTimeDbContextFactory.cs b/src/Tgstation.Server.Host/Models/Migrations/MySqlDesignTimeDbContextFactory.cs index b33b088ed2..fd55e611c1 100644 --- a/src/Tgstation.Server.Host/Models/Migrations/MySqlDesignTimeDbContextFactory.cs +++ b/src/Tgstation.Server.Host/Models/Migrations/MySqlDesignTimeDbContextFactory.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using Microsoft.Extensions.Logging; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Models.Migrations @@ -10,6 +9,6 @@ namespace Tgstation.Server.Host.Models.Migrations sealed class MySqlDesignTimeDbContextFactory : IDesignTimeDbContextFactory { /// - public MySqlDatabaseContext CreateDbContext(string[] args) => new MySqlDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new LoggerFactory(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); + public MySqlDatabaseContext CreateDbContext(string[] args) => new MySqlDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); } } diff --git a/src/Tgstation.Server.Host/Models/Migrations/SqlServerDesignTimeDbContextFactory.cs b/src/Tgstation.Server.Host/Models/Migrations/SqlServerDesignTimeDbContextFactory.cs index 935768080b..75a1b97053 100644 --- a/src/Tgstation.Server.Host/Models/Migrations/SqlServerDesignTimeDbContextFactory.cs +++ b/src/Tgstation.Server.Host/Models/Migrations/SqlServerDesignTimeDbContextFactory.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using Microsoft.Extensions.Logging; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Models.Migrations @@ -10,6 +9,6 @@ namespace Tgstation.Server.Host.Models.Migrations sealed class SqlServerDesignTimeDbContextFactory : IDesignTimeDbContextFactory { /// - public SqlServerDatabaseContext CreateDbContext(string[] args) => new SqlServerDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new LoggerFactory(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); + public SqlServerDatabaseContext CreateDbContext(string[] args) => new SqlServerDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); } } diff --git a/src/Tgstation.Server.Host/Models/Migrations/SqliteDesignTimeDbContextFactory.cs b/src/Tgstation.Server.Host/Models/Migrations/SqliteDesignTimeDbContextFactory.cs index 637bebfd0f..ece917a6b1 100644 --- a/src/Tgstation.Server.Host/Models/Migrations/SqliteDesignTimeDbContextFactory.cs +++ b/src/Tgstation.Server.Host/Models/Migrations/SqliteDesignTimeDbContextFactory.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using Microsoft.Extensions.Logging; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Models.Migrations @@ -10,6 +9,6 @@ namespace Tgstation.Server.Host.Models.Migrations sealed class SqliteDesignTimeDbContextFactory : IDesignTimeDbContextFactory { /// - public SqliteDatabaseContext CreateDbContext(string[] args) => new SqliteDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new LoggerFactory(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); + public SqliteDatabaseContext CreateDbContext(string[] args) => new SqliteDatabaseContext(new DbContextOptions(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher()))); } } diff --git a/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs b/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs index e88678bf23..0f70b29fcd 100644 --- a/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Tgstation.Server.Host.Configuration; @@ -15,9 +14,8 @@ namespace Tgstation.Server.Host.Models /// /// The for the /// The of for the - /// The for the /// The for the - public MySqlDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, ILoggerFactory loggerFactory, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, loggerFactory, databaseSeeder) + public MySqlDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, databaseSeeder) { } /// diff --git a/src/Tgstation.Server.Host/Models/SqlServerDatabaseContext.cs b/src/Tgstation.Server.Host/Models/SqlServerDatabaseContext.cs index 240f8ba1e7..19f6736cc9 100644 --- a/src/Tgstation.Server.Host/Models/SqlServerDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/SqlServerDatabaseContext.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Tgstation.Server.Host.Configuration; @@ -15,9 +14,8 @@ namespace Tgstation.Server.Host.Models /// /// The for the /// The of for the - /// The for the /// The for the - public SqlServerDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, ILoggerFactory loggerFactory, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, loggerFactory, databaseSeeder) + public SqlServerDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, databaseSeeder) { } /// diff --git a/src/Tgstation.Server.Host/Models/SqliteDatabaseContext.cs b/src/Tgstation.Server.Host/Models/SqliteDatabaseContext.cs index 0d6c1c94e3..57885f1e56 100644 --- a/src/Tgstation.Server.Host/Models/SqliteDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/SqliteDatabaseContext.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Tgstation.Server.Host.Configuration; @@ -15,9 +14,8 @@ namespace Tgstation.Server.Host.Models /// /// The for the /// The of for the - /// The for the /// The for the - public SqliteDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, ILoggerFactory loggerFactory, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, loggerFactory, databaseSeeder) + public SqliteDatabaseContext(DbContextOptions dbContextOptions, IOptions databaseConfiguration, IDatabaseSeeder databaseSeeder) : base(dbContextOptions, databaseConfiguration, databaseSeeder) { } /// diff --git a/src/Tgstation.Server.Host/appsettings.json b/src/Tgstation.Server.Host/appsettings.json index 12aa0e9cf9..f62fafa2f2 100644 --- a/src/Tgstation.Server.Host/appsettings.json +++ b/src/Tgstation.Server.Host/appsettings.json @@ -13,7 +13,7 @@ }, "EntityFramework": { "LogLevel": { - "Default": "Warning" + "Default": "Information" } } },