diff --git a/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs b/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs index c76de8dfb3..b276d5b171 100644 --- a/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs +++ b/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Persistence; namespace Umbraco.Core.Migrations @@ -13,7 +13,7 @@ namespace Umbraco.Core.Migrations /// /// Gets the logger. /// - ILogger Logger { get; } + ILogger Logger { get; } /// /// Gets the database instance. diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index f48bba9cf7..a3d7ee46d0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -419,7 +419,7 @@ namespace Umbraco.Core.Migrations.Install // upgrade var upgrader = new Upgrader(plan); - upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger); + upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _loggerFactory.CreateLogger(), _loggerFactory); var message = "

Upgrade completed!

"; diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationBase.cs b/src/Umbraco.Infrastructure/Migrations/MigrationBase.cs index 58edcae80a..b24313bebb 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationBase.cs @@ -1,6 +1,6 @@ using System; using NPoco; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Migrations.Expressions.Alter; using Umbraco.Core.Migrations.Expressions.Create; using Umbraco.Core.Migrations.Expressions.Delete; diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs b/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs index 0bb2bc11ae..5c53c3cc46 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Persistence; namespace Umbraco.Core.Migrations @@ -13,14 +13,14 @@ namespace Umbraco.Core.Migrations /// /// Initializes a new instance of the class. /// - public MigrationContext(IUmbracoDatabase database, ILogger logger) + public MigrationContext(IUmbracoDatabase database, ILogger logger) { Database = database ?? throw new ArgumentNullException(nameof(database)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); } /// - public ILogger Logger { get; } + public ILogger Logger { get; } /// public IUmbracoDatabase Database { get; } diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs b/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs index 199937d02e..56ba221205 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Text; +using Microsoft.Extensions.Logging; using NPoco; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs b/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs index de2770bf47..67e5d0b41a 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Scoping; using Type = System.Type; @@ -285,9 +285,10 @@ namespace Umbraco.Core.Migrations /// The state to start execution at. /// A migration builder. /// A logger. + /// /// The final state. /// The plan executes within the scope, which must then be completed. - public string Execute(IScope scope, string fromState, IMigrationBuilder migrationBuilder, ILogger logger) + public string Execute(IScope scope, string fromState, IMigrationBuilder migrationBuilder, ILogger logger, ILoggerFactory loggerFactory) { Validate(); @@ -303,7 +304,7 @@ namespace Umbraco.Core.Migrations if (!_transitions.TryGetValue(origState, out var transition)) ThrowOnUnknownInitialState(origState); - var context = new MigrationContext(scope.Database, logger); + var context = new MigrationContext(scope.Database, loggerFactory.CreateLogger()); context.PostMigrations.AddRange(_postMigrationTypes); while (transition != null) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs index f6df52bc1e..9096a14146 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs @@ -1,5 +1,5 @@ using System; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Services; @@ -40,7 +40,8 @@ namespace Umbraco.Core.Migrations.Upgrade /// A migration builder. /// A key-value service. /// A logger. - public void Execute(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger) + /// A logger factory + public void Execute(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger, ILoggerFactory loggerFactory) { if (scopeProvider == null) throw new ArgumentNullException(nameof(scopeProvider)); if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); @@ -64,7 +65,7 @@ namespace Umbraco.Core.Migrations.Upgrade } // execute plan - var state = plan.Execute(scope, currentState, migrationBuilder, logger); + var state = plan.Execute(scope, currentState, migrationBuilder, loggerFactory.CreateLogger(), loggerFactory); if (string.IsNullOrWhiteSpace(state)) throw new Exception("Plan execution returned an invalid null or empty state."); @@ -83,13 +84,13 @@ namespace Umbraco.Core.Migrations.Upgrade /// /// Executes as part of the upgrade scope and before all migrations have executed. /// - public virtual void BeforeMigrations(IScope scope, ILogger logger) + public virtual void BeforeMigrations(IScope scope, ILogger logger) { } /// /// Executes as part of the upgrade scope and after all migrations have executed. /// - public virtual void AfterMigrations(IScope scope, ILogger logger) + public virtual void AfterMigrations(IScope scope, ILogger logger) { } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs index 1110cbaa0e..6b1d734bc8 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core.IO; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Logging; using Umbraco.Core.Migrations.PostMigrations; using Umbraco.Core.Models; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs index 7c2164f58a..00092f3feb 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Logging; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs index 61e69fe234..79bbcece0d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs index 04b7ad8aef..20218dc2c6 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Migrations.PostMigrations; using Umbraco.Core.Models; using Umbraco.Core.Persistence; diff --git a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs index a9785697f4..f9b8566cfd 100644 --- a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs +++ b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Moq; using NPoco; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Migrations; using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence; @@ -24,7 +25,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CanExecute() { - var logger = Mock.Of(); + var loggerFactory = NullLoggerFactory.Instance; var database = new TestDatabase(); var scope = Mock.Of(); @@ -66,7 +67,7 @@ namespace Umbraco.Tests.Migrations var sourceState = kvs.GetValue("Umbraco.Tests.MigrationPlan") ?? string.Empty; // execute plan - state = plan.Execute(s, sourceState, migrationBuilder, logger); + state = plan.Execute(s, sourceState, migrationBuilder, loggerFactory.CreateLogger(), loggerFactory); // save new state kvs.SetValue("Umbraco.Tests.MigrationPlan", sourceState, state); diff --git a/src/Umbraco.Tests/Migrations/MigrationTests.cs b/src/Umbraco.Tests/Migrations/MigrationTests.cs index bfadd45b0d..46d9b04b1b 100644 --- a/src/Umbraco.Tests/Migrations/MigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/MigrationTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Semver; @@ -10,7 +11,6 @@ using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence; using Umbraco.Core.Scoping; using Umbraco.Core.Services; -using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.Migrations { @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Migrations throw new NotImplementedException(); } - + public IScopeContext Context { get; set; } public ISqlContext SqlContext { get; set; } @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Migrations [Test] public void RunGoodMigration() { - var migrationContext = new MigrationContext(Mock.Of(), Mock.Of()); + var migrationContext = new MigrationContext(Mock.Of(), Mock.Of>()); IMigration migration = new GoodMigration(migrationContext); migration.Migrate(); } @@ -71,7 +71,7 @@ namespace Umbraco.Tests.Migrations [Test] public void DetectBadMigration1() { - var migrationContext = new MigrationContext(Mock.Of(), Mock.Of()); + var migrationContext = new MigrationContext(Mock.Of(), Mock.Of>()); IMigration migration = new BadMigration1(migrationContext); Assert.Throws(() => migration.Migrate()); } @@ -79,7 +79,7 @@ namespace Umbraco.Tests.Migrations [Test] public void DetectBadMigration2() { - var migrationContext = new MigrationContext(Mock.Of(), Mock.Of()); + var migrationContext = new MigrationContext(Mock.Of(), Mock.Of>()); IMigration migration = new BadMigration2(migrationContext); Assert.Throws(() => migration.Migrate()); } diff --git a/src/Umbraco.Tests/Migrations/PostMigrationTests.cs b/src/Umbraco.Tests/Migrations/PostMigrationTests.cs index d9dcbc1d34..ba265b3fd2 100644 --- a/src/Umbraco.Tests/Migrations/PostMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/PostMigrationTests.cs @@ -1,8 +1,9 @@ using System; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging; using Moq; using NPoco; using NUnit.Framework; -using Umbraco.Core.Logging; using Umbraco.Core.Migrations; using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence; @@ -17,11 +18,10 @@ namespace Umbraco.Tests.Migrations [TestFixture] public class PostMigrationTests { + private static ILoggerFactory _loggerFactory = NullLoggerFactory.Instance; [Test] public void ExecutesPlanPostMigration() { - var logger = Mock.Of(); - var builder = Mock.Of(); Mock.Get(builder) .Setup(x => x.Build(It.IsAny(), It.IsAny())) @@ -54,7 +54,7 @@ namespace Umbraco.Tests.Migrations TestPostMigration.MigrateCount = 0; var upgrader = new Upgrader(plan); - upgrader.Execute(scopeProvider, builder, Mock.Of(), logger); + upgrader.Execute(scopeProvider, builder, Mock.Of(), _loggerFactory.CreateLogger(), _loggerFactory); Assert.AreEqual(1, TestPostMigration.MigrateCount); } @@ -62,8 +62,6 @@ namespace Umbraco.Tests.Migrations [Test] public void MigrationCanAddPostMigration() { - var logger = Mock.Of(); - var builder = Mock.Of(); Mock.Get(builder) .Setup(x => x.Build(It.IsAny(), It.IsAny())) @@ -97,10 +95,10 @@ namespace Umbraco.Tests.Migrations TestMigration.MigrateCount = 0; TestPostMigration.MigrateCount = 0; - new MigrationContext(database, logger); + new MigrationContext(database, _loggerFactory.CreateLogger()); var upgrader = new Upgrader(plan); - upgrader.Execute(scopeProvider, builder, Mock.Of(), logger); + upgrader.Execute(scopeProvider, builder, Mock.Of(), _loggerFactory.CreateLogger(), _loggerFactory); Assert.AreEqual(1, TestMigration.MigrateCount); Assert.AreEqual(1, TestPostMigration.MigrateCount); diff --git a/src/Umbraco.Tests/Persistence/SyntaxProvider/SqlCeSyntaxProviderTests.cs b/src/Umbraco.Tests/Persistence/SyntaxProvider/SqlCeSyntaxProviderTests.cs index 1d87bb35e7..a43e912ddf 100644 --- a/src/Umbraco.Tests/Persistence/SyntaxProvider/SqlCeSyntaxProviderTests.cs +++ b/src/Umbraco.Tests/Persistence/SyntaxProvider/SqlCeSyntaxProviderTests.cs @@ -1,10 +1,10 @@ using System; using System.Diagnostics; +using Microsoft.Extensions.Logging; using Moq; using NPoco; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Migrations; using Umbraco.Core.Migrations.Expressions.Common.Expressions; using Umbraco.Core.Migrations.Expressions.Create.Index; @@ -99,7 +99,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_NonClustered_CreatesNonClusteredIndex() { - var logger = Mock.Of(); + var logger = Mock.Of>(); var sqlSyntax = new SqlServerSyntaxProvider(); var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); var context = new MigrationContext(db, logger); @@ -120,7 +120,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Unique_CreatesUniqueNonClusteredIndex() { - var logger = Mock.Of(); + var logger = Mock.Of>(); var sqlSyntax = new SqlServerSyntaxProvider(); var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); var context = new MigrationContext(db, logger); @@ -141,7 +141,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Unique_CreatesUniqueNonClusteredIndex_Multi_Columnn() { - var logger = Mock.Of(); + var logger = Mock.Of>(); var sqlSyntax = new SqlServerSyntaxProvider(); var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); var context = new MigrationContext(db, logger); @@ -162,7 +162,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Clustered_CreatesClusteredIndex() { - var logger = Mock.Of(); + var logger = Mock.Of>(); var sqlSyntax = new SqlServerSyntaxProvider(); var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); var context = new MigrationContext(db, logger);