From 4b254a02a844706a101e50c82618d29d595ab4f9 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Thu, 17 Sep 2020 11:35:29 +0200 Subject: [PATCH] Use MS Ilogger for FileSystem --- src/Umbraco.Core/IO/FileSystems.cs | 30 +++++----- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 8 +-- src/Umbraco.Core/IO/ShadowWrapper.cs | 10 ++-- .../CompositionExtensions/FileSystems.cs | 6 +- src/Umbraco.Infrastructure/Scoping/Scope.cs | 10 ++-- .../Scoping/ScopeProvider.cs | 16 +++--- .../Repositories/TemplateRepositoryTest.cs | 4 +- .../Components/ComponentTests.cs | 6 +- .../IO/PhysicalFileSystemTests.cs | 4 +- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 55 ++++++++++--------- .../PartialViewRepositoryTests.cs | 3 +- .../Repositories/ScriptRepositoryTest.cs | 3 +- .../Repositories/StylesheetRepositoryTest.cs | 3 +- .../Scoping/ScopeEventDispatcherTests.cs | 3 +- .../Scoping/ScopeFileSystemsTests.cs | 6 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 4 +- .../Controllers/BackOfficeAssetsController.cs | 6 +- .../Runtime/BackOfficeComposer.cs | 4 +- 18 files changed, 95 insertions(+), 86 deletions(-) diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index acb0f2c895..0e5d0695dd 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -2,7 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; @@ -12,7 +12,8 @@ namespace Umbraco.Core.IO public class FileSystems : IFileSystems { private readonly IFactory _container; - private readonly ILogger _logger; + private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; private readonly IIOHelper _ioHelper; private readonly ConcurrentDictionary> _filesystems = new ConcurrentDictionary>(); @@ -36,10 +37,11 @@ namespace Umbraco.Core.IO #region Constructor // DI wants a public ctor - public FileSystems(IFactory container, ILogger logger, IIOHelper ioHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public FileSystems(IFactory container, ILogger logger, ILoggerFactory loggerFactory, IIOHelper ioHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { _container = container; _logger = logger; + _loggerFactory = loggerFactory; _ioHelper = ioHelper; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; @@ -126,17 +128,17 @@ namespace Umbraco.Core.IO // but it does not really matter what we return - here, null private object CreateWellKnownFileSystems() { - var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, Constants.SystemDirectories.MacroPartials); - var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, Constants.SystemDirectories.PartialViews); - var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, _globalSettings.UmbracoCssPath); - var scriptsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, _globalSettings.UmbracoScriptsPath); - var mvcViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, Constants.SystemDirectories.MvcViews); + var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), Constants.SystemDirectories.MacroPartials); + var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), Constants.SystemDirectories.PartialViews); + var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), _globalSettings.UmbracoCssPath); + var scriptsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), _globalSettings.UmbracoScriptsPath); + var mvcViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), Constants.SystemDirectories.MvcViews); - _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, _ioHelper, _hostingEnvironment, _logger,"macro-partials", IsScoped); - _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, _ioHelper, _hostingEnvironment, _logger,"partials", IsScoped); - _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, _ioHelper, _hostingEnvironment,_logger,"css", IsScoped); - _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, _ioHelper, _hostingEnvironment,_logger,"scripts", IsScoped); - _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, _ioHelper, _hostingEnvironment,_logger,"views", IsScoped); + _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory,"macro-partials", IsScoped); + _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory,"partials", IsScoped); + _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory,"css", IsScoped); + _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory,"scripts", IsScoped); + _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory,"views", IsScoped); // TODO: do we need a lock here? _shadowWrappers.Add(_macroPartialFileSystem); @@ -277,7 +279,7 @@ namespace Umbraco.Core.IO { lock (_shadowLocker) { - var wrapper = new ShadowWrapper(filesystem, _ioHelper, _hostingEnvironment, _logger, shadowPath, IsScoped); + var wrapper = new ShadowWrapper(filesystem, _ioHelper, _hostingEnvironment, _loggerFactory, shadowPath, IsScoped); if (_shadowCurrentId != null) wrapper.Shadow(_shadowCurrentId); _shadowWrappers.Add(wrapper); diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index 105ddf056c..04e3df6ab3 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -2,18 +2,18 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core.Exceptions; using Umbraco.Core.Composing; using System.Threading; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; namespace Umbraco.Core.IO { public class PhysicalFileSystem : IFileSystem { private readonly IIOHelper _ioHelper; - private readonly ILogger _logger; + private readonly ILogger _logger; // the rooted, filesystem path, using directory separator chars, NOT ending with a separator // eg "c:" or "c:\path\to\site" or "\\server\path" @@ -30,7 +30,7 @@ namespace Umbraco.Core.IO // virtualRoot should be "~/path/to/root" eg "~/Views" // the "~/" is mandatory. - public PhysicalFileSystem(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, string virtualRoot) + public PhysicalFileSystem(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, string virtualRoot) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); if (hostingEnvironment == null) throw new ArgumentNullException(nameof(hostingEnvironment)); @@ -45,7 +45,7 @@ namespace Umbraco.Core.IO _rootUrl = EnsureUrlSeparatorChar(hostingEnvironment.ToAbsolute(virtualRoot)).TrimEnd('/'); } - public PhysicalFileSystem(IIOHelper ioHelper,IHostingEnvironment hostingEnvironment, ILogger logger, string rootPath, string rootUrl) + public PhysicalFileSystem(IIOHelper ioHelper,IHostingEnvironment hostingEnvironment, ILogger logger, string rootPath, string rootUrl) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Core/IO/ShadowWrapper.cs index 7ddd6a48b7..83fe5aafe7 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Core/IO/ShadowWrapper.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core.Composing; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; namespace Umbraco.Core.IO { @@ -19,14 +19,14 @@ namespace Umbraco.Core.IO private string _shadowDir; private readonly IIOHelper _ioHelper; private readonly IHostingEnvironment _hostingEnvironment; - private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; - public ShadowWrapper(IFileSystem innerFileSystem, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, string shadowPath, Func isScoped = null) + public ShadowWrapper(IFileSystem innerFileSystem, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, string shadowPath, Func isScoped = null) { _innerFileSystem = innerFileSystem; _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _loggerFactory = loggerFactory; _shadowPath = shadowPath; _isScoped = isScoped; } @@ -66,7 +66,7 @@ namespace Umbraco.Core.IO var virt = ShadowFsPath + "/" + id + "/" + _shadowPath; _shadowDir = _ioHelper.MapPath(virt); Directory.CreateDirectory(_shadowDir); - var tempfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, virt); + var tempfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), virt); _shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs); } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs index 9dc130fcba..98dd585981 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs @@ -1,8 +1,8 @@ -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Logging; +using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.IO.MediaPathSchemes; -using Umbraco.Core.Logging; namespace Umbraco.Core.Composing.CompositionExtensions { @@ -96,7 +96,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions { var ioHelper = factory.GetInstance(); var hostingEnvironment = factory.GetInstance(); - var logger = factory.GetInstance(); + var logger = factory.GetInstance>(); var globalSettings = factory.GetInstance(); var rootPath = hostingEnvironment.MapPathWebRoot(globalSettings.UmbracoMediaPath); diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index d1f60666b9..d22e6b0de8 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -1,11 +1,11 @@ using System; using System.Data; +using Microsoft.Extensions.Logging; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; namespace Umbraco.Core.Scoping @@ -19,7 +19,7 @@ namespace Umbraco.Core.Scoping private readonly ScopeProvider _scopeProvider; private readonly ICoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly ITypeFinder _typeFinder; private readonly IsolationLevel _isolationLevel; @@ -41,7 +41,7 @@ namespace Umbraco.Core.Scoping private Scope(ScopeProvider scopeProvider, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, - ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, IScopeContext scopeContext, bool detachable, + ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, IScopeContext scopeContext, bool detachable, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, IEventDispatcher eventDispatcher = null, @@ -120,7 +120,7 @@ namespace Umbraco.Core.Scoping public Scope(ScopeProvider scopeProvider, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, - ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, bool detachable, IScopeContext scopeContext, + ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, bool detachable, IScopeContext scopeContext, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, IEventDispatcher eventDispatcher = null, @@ -134,7 +134,7 @@ namespace Umbraco.Core.Scoping public Scope(ScopeProvider scopeProvider, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, - ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, + ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, IEventDispatcher eventDispatcher = null, diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 610f308b96..f11ec145e0 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Data; +using Microsoft.Extensions.Logging; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Current = Umbraco.Composing.Current; @@ -22,20 +22,22 @@ namespace Umbraco.Core.Scoping /// internal class ScopeProvider : IScopeProvider, IScopeAccessor { - private readonly ILogger _logger; + private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; private readonly ITypeFinder _typeFinder; private readonly IRequestCache _requestCache; private readonly FileSystems _fileSystems; private readonly ICoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; - public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) + public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ILoggerFactory loggerFactory, ITypeFinder typeFinder, IRequestCache requestCache) { DatabaseFactory = databaseFactory; _fileSystems = fileSystems; _coreDebugSettings = coreDebugSettings; _mediaFileSystem = mediaFileSystem; _logger = logger; + _loggerFactory = loggerFactory; _typeFinder = typeFinder; _requestCache = requestCache; // take control of the FileSystems @@ -93,7 +95,7 @@ namespace Umbraco.Core.Scoping { // first, null-register the existing value var ambientScope = CallContext.GetData(ScopeItemKey); - + if (ambientScope != null) RegisterContext(ambientScope, null); // then register the new value var scope = value as IScope; @@ -255,7 +257,7 @@ namespace Umbraco.Core.Scoping IEventDispatcher eventDispatcher = null, bool? scopeFileSystems = null) { - return new Scope(this, _coreDebugSettings, _mediaFileSystem, _logger, _typeFinder, _fileSystems, true, null, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems); + return new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _typeFinder, _fileSystems, true, null, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems); } /// @@ -311,13 +313,13 @@ namespace Umbraco.Core.Scoping { var ambientContext = AmbientContext; var newContext = ambientContext == null ? new ScopeContext() : null; - var scope = new Scope(this, _coreDebugSettings, _mediaFileSystem, _logger, _typeFinder, _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); + var scope = new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _typeFinder, _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); // assign only if scope creation did not throw! SetAmbient(scope, newContext ?? ambientContext); return scope; } - var nested = new Scope(this, _coreDebugSettings, _mediaFileSystem, _logger, _typeFinder, _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); + var nested = new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _typeFinder, _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); SetAmbient(nested, AmbientContext); return nested; } diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs index 3e11bbb72f..67ea60788c 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs @@ -38,7 +38,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var testHelper = new TestHelper(); _fileSystems = Mock.Of(); - var viewsFileSystem = new PhysicalFileSystem(IOHelper, testHelper.GetHostingEnvironment(), Logger, Constants.SystemDirectories.MvcViews); + var viewsFileSystem = new PhysicalFileSystem(IOHelper, testHelper.GetHostingEnvironment(), ConsoleLoggerFactory.CreateLogger(), Constants.SystemDirectories.MvcViews); Mock.Get(_fileSystems).Setup(x => x.MvcViewsFileSystem).Returns(viewsFileSystem); } @@ -570,7 +570,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories _fileSystems = null; //Delete all files - var fsViews = new PhysicalFileSystem(IOHelper, testHelper.GetHostingEnvironment(), Logger, Constants.SystemDirectories.MvcViews); + var fsViews = new PhysicalFileSystem(IOHelper, testHelper.GetHostingEnvironment(), ConsoleLoggerFactory.CreateLogger(), Constants.SystemDirectories.MvcViews); var views = fsViews.GetFiles("", "*.cshtml"); foreach (var file in views) fsViews.DeleteFile(file); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 5dc8dd801d..5772657f11 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -34,13 +35,12 @@ namespace Umbraco.Tests.Components var mock = new Mock(); var logger = Mock.Of(); - var umbLogger = Mock.Of(); var typeFinder = TestHelper.GetTypeFinder(); var f = new UmbracoDatabaseFactory(Mock.Of>(), Mock.Of(), SettingsForTests.DefaultGlobalSettings, Mock.Of(), new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); - var fs = new FileSystems(mock.Object, umbLogger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); + var fs = new FileSystems(mock.Object, Mock.Of>(), NullLoggerFactory.Instance, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); var coreDebug = Mock.Of(); var mediaFileSystem = Mock.Of(); - var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, umbLogger, typeFinder, NoAppCache.Instance); + var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, Mock.Of>(), Mock.Of(), typeFinder, NoAppCache.Instance); mock.Setup(x => x.GetInstance(typeof (ILogger))).Returns(logger); mock.Setup(x => x.GetInstance(typeof (IProfilingLogger))).Returns(new ProfilingLogger(Mock.Of(), Mock.Of())); diff --git a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs index f1e705c9cb..bd26bbcc66 100644 --- a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs @@ -2,10 +2,10 @@ using System.IO; using System.Text; using System.Threading; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers; @@ -16,7 +16,7 @@ namespace Umbraco.Tests.IO public class PhysicalFileSystemTests : AbstractFileSystemTests { public PhysicalFileSystemTests() - : base(new PhysicalFileSystem(TestHelper.IOHelper, TestHelper.GetHostingEnvironment(), Mock.Of(), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"), "/Media/")) + : base(new PhysicalFileSystem(TestHelper.IOHelper, TestHelper.GetHostingEnvironment(), Mock.Of>(), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"), "/Media/")) { } [SetUp] diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 07a04479a4..e9f2a307f8 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; @@ -53,7 +54,7 @@ namespace Umbraco.Tests.IO public void ShadowDeleteDirectory() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -91,7 +92,7 @@ namespace Umbraco.Tests.IO public void ShadowDeleteDirectoryInDir() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -144,7 +145,7 @@ namespace Umbraco.Tests.IO public void ShadowDeleteFile() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -187,7 +188,7 @@ namespace Umbraco.Tests.IO public void ShadowDeleteFileInDir() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -247,7 +248,7 @@ namespace Umbraco.Tests.IO public void ShadowCantCreateFile() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -270,7 +271,7 @@ namespace Umbraco.Tests.IO public void ShadowCreateFile() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -313,7 +314,7 @@ namespace Umbraco.Tests.IO public void ShadowCreateFileInDir() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -357,7 +358,7 @@ namespace Umbraco.Tests.IO public void ShadowAbort() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -383,7 +384,7 @@ namespace Umbraco.Tests.IO public void ShadowComplete() { var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -422,7 +423,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeComplete() { - var logger = Mock.Of(); + var loggerFactory = NullLoggerFactory.Instance; var ioHelper = TestHelper.IOHelper; var hostingEnvironment = TestHelper.GetHostingEnvironment(); @@ -433,10 +434,10 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, loggerFactory.CreateLogger(), loggerFactory, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem(phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -519,7 +520,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithFileConflict() { - var logger = Mock.Of(); + var loggerFactory = NullLoggerFactory.Instance; var ioHelper = TestHelper.IOHelper; var hostingEnvironment = TestHelper.GetHostingEnvironment(); @@ -529,10 +530,10 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, loggerFactory.CreateLogger(), loggerFactory, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -574,7 +575,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithDirectoryConflict() { - var logger = Mock.Of(); + var loggerFactory = NullLoggerFactory.Instance; var ioHelper = TestHelper.IOHelper; var hostingEnvironment = TestHelper.GetHostingEnvironment(); @@ -584,10 +585,10 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, loggerFactory.CreateLogger(), loggerFactory, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper)fs.InnerFileSystem; @@ -694,7 +695,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -730,7 +731,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -769,7 +770,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -805,7 +806,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -844,7 +845,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -895,7 +896,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -933,7 +934,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); @@ -976,7 +977,7 @@ namespace Umbraco.Tests.IO { // Arrange var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); + var logger = Mock.Of>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var path = ioHelper.MapPath("FileSysTests"); diff --git a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs index 618723fdf7..e50de3190b 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -23,7 +24,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.SetUp(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, Constants.SystemDirectories.MvcViews + "/Partials/"); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory_.CreateLogger(), Constants.SystemDirectories.MvcViews + "/Partials/"); } protected override void Compose() diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 0a33c0af0b..8a060a4ba2 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -30,7 +31,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, SettingsForTests.GenerateMockGlobalSettings().UmbracoScriptsPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory_.CreateLogger(), SettingsForTests.GenerateMockGlobalSettings().UmbracoScriptsPath); Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index f4558dca2d..298f3eb278 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -3,6 +3,7 @@ using System.Data; using System.IO; using System.Linq; using System.Text; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -29,7 +30,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, SettingsForTests.GenerateMockGlobalSettings().UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory_.CreateLogger(), SettingsForTests.GenerateMockGlobalSettings().UmbracoCssPath); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index aff55de4df..f31158b319 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -39,7 +40,7 @@ namespace Umbraco.Tests.Scoping _testObjects = new TestObjects(register); - composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance(), TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment())); + composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance>(), factory.TryGetInstance(), TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment())); composition.WithCollectionBuilder(); composition.Configs.Add(() => SettingsForTests.DefaultGlobalSettings); diff --git a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs index 2e2ebf392c..8c98bc99ff 100644 --- a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -9,7 +10,6 @@ using Umbraco.Core.IO; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Core.Composing.CompositionExtensions; -using Umbraco.Core.Logging; using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.Scoping @@ -55,7 +55,7 @@ namespace Umbraco.Tests.Scoping [TestCase(false)] public void CreateMediaTest(bool complete) { - var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Mock.Of(), IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Mock.Of>(), IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt")); @@ -88,7 +88,7 @@ namespace Umbraco.Tests.Scoping [Test] public void MultiThread() { - var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Mock.Of(),IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Mock.Of>(),IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; var scopeProvider = ScopeProvider; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 58c80671f5..ac2c59e2b8 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -88,10 +88,10 @@ namespace Umbraco.Tests.TestHelpers } typeFinder ??= new TypeFinder(loggerFactory.CreateLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); - fileSystems ??= new FileSystems(Current.Factory, loggerFactory.CreateLogger(), TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); + fileSystems ??= new FileSystems(Current.Factory, loggerFactory.CreateLogger(), loggerFactory, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); var coreDebug = TestHelper.CoreDebugSettings; var mediaFileSystem = Mock.Of(); - var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, coreDebug, mediaFileSystem, loggerFactory.CreateLogger(), typeFinder, NoAppCache.Instance); + var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, coreDebug, mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, typeFinder, NoAppCache.Instance); return scopeProvider; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index 7cbeb8e86e..7d336f29d7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Mvc; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Web.Common.Attributes; namespace Umbraco.Web.BackOffice.Controllers @@ -17,9 +17,9 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly IFileSystem _jsLibFileSystem; - public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IGlobalSettings globalSettings) + public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IGlobalSettings globalSettings) { - _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.UmbracoPath + Path.DirectorySeparatorChar + "lib"); + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), globalSettings.UmbracoPath + Path.DirectorySeparatorChar + "lib"); } [HttpGet] diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index 600602f5b5..648fa6b031 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -1,9 +1,9 @@ using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Routing; @@ -43,7 +43,7 @@ namespace Umbraco.Web.BackOffice.Runtime new PhysicalFileSystem( factory.GetInstance(), factory.GetInstance(), - factory.GetInstance(), + factory.GetInstance>(), "~/")); } }