From 120e163682d601554eaa6c9d4cda52dd9f8c66b0 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 16 Sep 2020 13:08:27 +0200 Subject: [PATCH] Begin trying to replace logger in Current --- src/Umbraco.Core/Composing/Current.cs | 7 +++-- src/Umbraco.Core/Composing/TypeFinder.cs | 6 ++-- src/Umbraco.Core/Models/Member.cs | 3 +- src/Umbraco.Core/Runtime/MainDom.cs | 6 ++-- src/Umbraco.Core/UriExtensions.cs | 1 + .../UmbracoServiceProviderFactory.cs | 2 +- .../HealthCheck/HealthCheckResults.cs | 2 +- .../Models/PropertyTagsExtensions.cs | 1 + .../Persistence/DbConnectionExtensions.cs | 2 +- .../SqlSyntax/SqlServerSyntaxProvider.cs | 3 +- .../Persistence/UmbracoDatabase.cs | 8 +++--- .../Persistence/UmbracoDatabaseFactory.cs | 16 ++++++----- .../PropertyEditors/DataValueEditor.cs | 2 +- .../ValueConverters/GridValueConverter.cs | 2 +- .../ImageCropperValueConverter.cs | 2 +- .../ValueConverters/JsonValueConverter.cs | 2 +- .../Routing/NotFoundHandlerHelper.cs | 2 +- .../Runtime/CoreRuntime.cs | 2 +- .../Runtime/MainDomSemaphoreLock.cs | 6 ++-- .../Runtime/SqlMainDomLock.cs | 9 +++--- .../LocalizedTextServiceFileSources.cs | 2 ++ src/Umbraco.Infrastructure/Suspendable.cs | 4 +-- .../Sync/ServerMessengerBase.cs | 2 +- .../TypeFinderBenchmarks.cs | 8 +++--- .../Umbraco.Tests.Benchmarks.csproj | 3 ++ src/Umbraco.Tests.Common/TestHelperBase.cs | 2 +- .../Umbraco.Core/Composing/TypeFinderTests.cs | 9 ++++-- .../Integration/ContentEventsTests.cs | 4 +-- .../DictionaryPublishedContent.cs | 2 +- .../LegacyXmlPublishedCache/PreviewContent.cs | 2 +- .../PublishedMediaCache.cs | 2 +- .../LegacyXmlPublishedCache/XmlStore.cs | 2 +- .../Services/ContentServicePerformanceTest.cs | 1 + src/Umbraco.Tests/TestHelpers/TestHelper.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 28 +++++++++++++++++-- .../ImageCropperTemplateExtensions.cs | 1 + .../UmbracoCoreServiceCollectionExtensions.cs | 11 ++++---- .../AspNet/AspNetBackOfficeInfo.cs | 6 ++-- src/Umbraco.Web/CdfLogger.cs | 4 +-- src/Umbraco.Web/Composing/Current.cs | 2 +- src/Umbraco.Web/ImageProcessorLogger.cs | 2 +- src/Umbraco.Web/Logging/OwinLogger.cs | 2 +- .../Mvc/AdminTokenAuthorizeAttribute.cs | 4 +-- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 2 +- .../AuthenticationOptionsExtensions.cs | 1 + src/Umbraco.Web/Security/MembershipHelper.cs | 3 +- .../Security/MembershipProviderBase.cs | 2 +- .../Providers/UmbracoMembershipProvider.cs | 2 +- src/Umbraco.Web/UmbracoApplication.cs | 9 +++--- src/Umbraco.Web/UmbracoApplicationBase.cs | 28 +++++++++++++++---- src/Umbraco.Web/UmbracoHelper.cs | 1 + src/Umbraco.Web/UmbracoHttpHandler.cs | 1 + src/Umbraco.Web/UmbracoInjectedModule.cs | 2 +- src/Umbraco.Web/UmbracoModule.cs | 2 +- src/Umbraco.Web/UmbracoWebService.cs | 2 ++ .../Filters/AngularAntiForgeryHelper.cs | 2 +- .../FileUploadCleanupFilterAttribute.cs | 2 +- .../WebApi/UnhandledExceptionLogger.cs | 2 +- 58 files changed, 157 insertions(+), 93 deletions(-) diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 1ca99e1348..fb2c82030a 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -6,13 +6,14 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging.Abstractions; using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Composing { public static class Current { - private static ILogger _logger = new NullLogger(); + private static Microsoft.Extensions.Logging.ILogger _logger = new NullLogger(); private static ILoggerFactory _loggerFactory; private static Configs _configs; private static IIOHelper _ioHelper; @@ -20,7 +21,7 @@ namespace Umbraco.Composing private static IBackOfficeInfo _backOfficeInfo; private static IProfiler _profiler; - public static ILogger Logger => EnsureInitialized(_logger); + public static Microsoft.Extensions.Logging.ILogger Logger => EnsureInitialized(_logger); public static Configs Configs => EnsureInitialized(_configs); public static IIOHelper IOHelper => EnsureInitialized(_ioHelper); public static IHostingEnvironment HostingEnvironment => EnsureInitialized(_hostingEnvironment); @@ -40,7 +41,7 @@ namespace Umbraco.Composing } public static void Initialize( - ILogger logger, + Microsoft.Extensions.Logging.ILogger logger, Configs configs, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, diff --git a/src/Umbraco.Core/Composing/TypeFinder.cs b/src/Umbraco.Core/Composing/TypeFinder.cs index 0d4faf261b..4cfcd9090c 100644 --- a/src/Umbraco.Core/Composing/TypeFinder.cs +++ b/src/Umbraco.Core/Composing/TypeFinder.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Security; using System.Text; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Core.Composing { @@ -14,7 +14,7 @@ namespace Umbraco.Core.Composing /// public class TypeFinder : ITypeFinder { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IAssemblyProvider _assemblyProvider; private readonly IRuntimeHash _runtimeHash; private volatile HashSet _localFilteredAssemblyCache; @@ -26,7 +26,7 @@ namespace Umbraco.Core.Composing // used for benchmark tests internal bool QueryWithReferencingAssemblies = true; - public TypeFinder(ILogger logger, IAssemblyProvider assemblyProvider, IRuntimeHash runtimeHash, ITypeFinderConfig typeFinderConfig = null) + public TypeFinder(ILogger logger, IAssemblyProvider assemblyProvider, IRuntimeHash runtimeHash, ITypeFinderConfig typeFinderConfig = null) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _assemblyProvider = assemblyProvider; diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index d22636dd68..d155db8b7c 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.ComponentModel; using System.Runtime.Serialization; +using Microsoft.Extensions.Logging; using Umbraco.Composing; -using Umbraco.Core.Logging; + namespace Umbraco.Core.Models { diff --git a/src/Umbraco.Core/Runtime/MainDom.cs b/src/Umbraco.Core/Runtime/MainDom.cs index cf369ef720..797dfa36e1 100644 --- a/src/Umbraco.Core/Runtime/MainDom.cs +++ b/src/Umbraco.Core/Runtime/MainDom.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Threading; +using Microsoft.Extensions.Logging; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; namespace Umbraco.Core.Runtime { @@ -20,7 +20,7 @@ namespace Umbraco.Core.Runtime { #region Vars - private readonly ILogger _logger; + private readonly ILogger _logger; private IApplicationShutdownRegistry _hostingEnvironment; private readonly IMainDomLock _mainDomLock; @@ -42,7 +42,7 @@ namespace Umbraco.Core.Runtime #region Ctor // initializes a new instance of MainDom - public MainDom(ILogger logger, IMainDomLock systemLock) + public MainDom(ILogger logger, IMainDomLock systemLock) { _logger = logger; _mainDomLock = systemLock; diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 5ecbc38183..3ecc919c10 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; diff --git a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs index 56a972a64b..d293097144 100644 --- a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs +++ b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs @@ -85,7 +85,7 @@ namespace Umbraco.Core.Composing { // after cross wiring, configure "Current" Current.Initialize( - _container.GetInstance(), + _container.GetInstance>(), _container.GetInstance(), _container.GetInstance(), _container.GetInstance(), diff --git a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs index 393a78308b..7eebf61b22 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs @@ -5,7 +5,7 @@ using System.Text; using HeyRed.MarkdownSharp; using Umbraco.Composing; using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Web.HealthCheck { diff --git a/src/Umbraco.Infrastructure/Models/PropertyTagsExtensions.cs b/src/Umbraco.Infrastructure/Models/PropertyTagsExtensions.cs index ff3ad57585..bea07879fb 100644 --- a/src/Umbraco.Infrastructure/Models/PropertyTagsExtensions.cs +++ b/src/Umbraco.Infrastructure/Models/PropertyTagsExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Composing; diff --git a/src/Umbraco.Infrastructure/Persistence/DbConnectionExtensions.cs b/src/Umbraco.Infrastructure/Persistence/DbConnectionExtensions.cs index a17692269e..e00288d94c 100644 --- a/src/Umbraco.Infrastructure/Persistence/DbConnectionExtensions.cs +++ b/src/Umbraco.Infrastructure/Persistence/DbConnectionExtensions.cs @@ -3,9 +3,9 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Linq; +using Microsoft.Extensions.Logging; using StackExchange.Profiling.Data; using Umbraco.Composing; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; namespace Umbraco.Core.Persistence diff --git a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs index 0c69fd7ebc..a87c9bdfa6 100644 --- a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs +++ b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs @@ -4,6 +4,7 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Linq; +using Microsoft.Extensions.Logging; using NPoco; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.DatabaseModelDefinitions; @@ -105,7 +106,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax } } - internal ServerVersionInfo GetSetVersion(string connectionString, string providerName, ILogger logger) + internal ServerVersionInfo GetSetVersion(string connectionString, string providerName, Microsoft.Extensions.Logging.ILogger logger) { //var factory = DbProviderFactories.GetFactory(providerName); var factory = SqlClientFactory.Instance; diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs index 41348507d3..37c47da50d 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs @@ -5,9 +5,9 @@ using System.Data.Common; using System.Data.SqlClient; using System.Linq; using System.Text; +using Microsoft.Extensions.Logging; using NPoco; using StackExchange.Profiling; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; using Umbraco.Core.Persistence.SqlSyntax; @@ -23,7 +23,7 @@ namespace Umbraco.Core.Persistence /// public class UmbracoDatabase : Database, IUmbracoDatabase { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IBulkSqlInsertProvider _bulkSqlInsertProvider; private readonly RetryPolicy _connectionRetryPolicy; private readonly RetryPolicy _commandRetryPolicy; @@ -39,7 +39,7 @@ namespace Umbraco.Core.Persistence /// Used by UmbracoDatabaseFactory to create databases. /// Also used by DatabaseBuilder for creating databases and installing/upgrading. /// - public UmbracoDatabase(string connectionString, ISqlContext sqlContext, DbProviderFactory provider, ILogger logger, IBulkSqlInsertProvider bulkSqlInsertProvider, RetryPolicy connectionRetryPolicy = null, RetryPolicy commandRetryPolicy = null) + public UmbracoDatabase(string connectionString, ISqlContext sqlContext, DbProviderFactory provider, ILogger logger, IBulkSqlInsertProvider bulkSqlInsertProvider, RetryPolicy connectionRetryPolicy = null, RetryPolicy commandRetryPolicy = null) : base(connectionString, sqlContext.DatabaseType, provider, sqlContext.SqlSyntax.DefaultIsolationLevel) { SqlContext = sqlContext; @@ -58,7 +58,7 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the class. /// /// Internal for unit tests only. - internal UmbracoDatabase(DbConnection connection, ISqlContext sqlContext, ILogger logger, IBulkSqlInsertProvider bulkSqlInsertProvider) + internal UmbracoDatabase(DbConnection connection, ISqlContext sqlContext, ILogger logger, IBulkSqlInsertProvider bulkSqlInsertProvider) : base(connection, sqlContext.DatabaseType, sqlContext.SqlSyntax.DefaultIsolationLevel) { SqlContext = sqlContext; diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index b1e7e0e8e8..d3c9518b18 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -2,11 +2,11 @@ using System.Data.Common; using System.Data.SqlClient; using System.Threading; +using Microsoft.Extensions.Logging; using NPoco; using NPoco.FluentMappings; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.SqlSyntax; @@ -30,7 +30,8 @@ namespace Umbraco.Core.Persistence private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator; private readonly IGlobalSettings _globalSettings; private readonly Lazy _mappers; - private readonly ILogger _logger; + private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; private object _lock = new object(); @@ -70,8 +71,8 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by core runtime. - public UmbracoDatabaseFactory(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) - : this(logger, globalSettings, connectionStrings, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, ILoggerFactory loggerFactory, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) + : this(logger, loggerFactory, globalSettings, connectionStrings, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) { } @@ -80,7 +81,7 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by the other ctor and in tests. - public UmbracoDatabaseFactory(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, string connectionStringName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, ILoggerFactory loggerFactory, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, string connectionStringName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) { if (connectionStringName == null) throw new ArgumentNullException(nameof(connectionStringName)); if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionStringName)); @@ -89,6 +90,7 @@ namespace Umbraco.Core.Persistence _mappers = mappers ?? throw new ArgumentNullException(nameof(mappers)); _dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _loggerFactory = loggerFactory; var settings = connectionStrings[connectionStringName]; @@ -115,7 +117,7 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used in tests. - public UmbracoDatabaseFactory(ILogger logger, string connectionString, string providerName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, string connectionString, string providerName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) { _mappers = mappers ?? throw new ArgumentNullException(nameof(mappers)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -312,7 +314,7 @@ namespace Umbraco.Core.Persistence // method used by NPoco's UmbracoDatabaseFactory to actually create the database instance private UmbracoDatabase CreateDatabaseInstance() { - return new UmbracoDatabase(ConnectionString, SqlContext, DbProviderFactory, _logger, _bulkSqlInsertProvider, _connectionRetryPolicy, _commandRetryPolicy); + return new UmbracoDatabase(ConnectionString, SqlContext, DbProviderFactory, _loggerFactory.CreateLogger(), _bulkSqlInsertProvider, _connectionRetryPolicy, _commandRetryPolicy); } protected override void DisposeResources() diff --git a/src/Umbraco.Infrastructure/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/DataValueEditor.cs index 342e1cab3b..df9a06515c 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/DataValueEditor.cs @@ -4,11 +4,11 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; using System.Xml.Linq; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Composing; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; using Umbraco.Core.PropertyEditors.Validators; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs index 8addda00dd..2dfcf4bda0 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -1,10 +1,10 @@ using System; using System.Linq; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Composing; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs index 2feb676549..1f4bb330e8 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs @@ -1,8 +1,8 @@ using System; using System.Globalization; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Composing; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/JsonValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/JsonValueConverter.cs index 6ce8a47925..972d8f56fe 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/JsonValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/JsonValueConverter.cs @@ -1,8 +1,8 @@ using System; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Composing; diff --git a/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs index a46b0be150..4412a40e59 100644 --- a/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs +++ b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs @@ -1,10 +1,10 @@ using System; using System.Globalization; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Xml; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 4c0a088f3e..ec59837570 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -13,7 +13,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; -using ILogger = Umbraco.Core.Logging.ILogger; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Umbraco.Core.Runtime { diff --git a/src/Umbraco.Infrastructure/Runtime/MainDomSemaphoreLock.cs b/src/Umbraco.Infrastructure/Runtime/MainDomSemaphoreLock.cs index 37c1244e08..eed13f5060 100644 --- a/src/Umbraco.Infrastructure/Runtime/MainDomSemaphoreLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/MainDomSemaphoreLock.cs @@ -1,8 +1,8 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; namespace Umbraco.Core.Runtime { @@ -16,10 +16,10 @@ namespace Umbraco.Core.Runtime // event wait handle used to notify current main domain that it should // release the lock because a new domain wants to be the main domain private readonly EventWaitHandle _signal; - private readonly ILogger _logger; + private readonly ILogger _logger; private IDisposable _lockRelease; - public MainDomSemaphoreLock(ILogger logger, IHostingEnvironment hostingEnvironment) + public MainDomSemaphoreLock(ILogger logger, IHostingEnvironment hostingEnvironment) { var lockName = "UMBRACO-" + MainDom.GetMainDomId(hostingEnvironment) + "-MAINDOM-LCK"; _systemLock = new SystemLock(lockName); diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index 71633c3972..b4385654c9 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -6,9 +6,9 @@ using System.Linq; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Mappers; @@ -21,7 +21,7 @@ namespace Umbraco.Core.Runtime private string _lockId; private const string MainDomKeyPrefix = "Umbraco.Core.Runtime.SqlMainDom"; private const string UpdatedSuffix = "_updated"; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; private IUmbracoDatabase _db; private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); @@ -31,13 +31,14 @@ namespace Umbraco.Core.Runtime private bool _errorDuringAcquiring; private object _locker = new object(); - public SqlMainDomLock(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, IDbProviderFactoryCreator dbProviderFactoryCreator, IHostingEnvironment hostingEnvironment) + public SqlMainDomLock(ILogger logger, ILoggerFactory loggerFactory, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, IDbProviderFactoryCreator dbProviderFactoryCreator, IHostingEnvironment hostingEnvironment) { // unique id for our appdomain, this is more unique than the appdomain id which is just an INT counter to its safer _lockId = Guid.NewGuid().ToString(); _logger = logger; _hostingEnvironment = hostingEnvironment; - _dbFactory = new UmbracoDatabaseFactory(_logger, + _dbFactory = new UmbracoDatabaseFactory(loggerFactory.CreateLogger(), + loggerFactory, globalSettings, connectionStrings, Constants.System.UmbracoConnectionName, diff --git a/src/Umbraco.Infrastructure/Services/Implement/LocalizedTextServiceFileSources.cs b/src/Umbraco.Infrastructure/Services/Implement/LocalizedTextServiceFileSources.cs index 30c03f1478..905361fe2f 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/LocalizedTextServiceFileSources.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/LocalizedTextServiceFileSources.cs @@ -9,6 +9,8 @@ using Umbraco.Composing; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Core.Services.Implement { diff --git a/src/Umbraco.Infrastructure/Suspendable.cs b/src/Umbraco.Infrastructure/Suspendable.cs index 57ef386c2e..e03931d0d7 100644 --- a/src/Umbraco.Infrastructure/Suspendable.cs +++ b/src/Umbraco.Infrastructure/Suspendable.cs @@ -1,6 +1,6 @@ -using Umbraco.Composing; +using Microsoft.Extensions.Logging; +using Umbraco.Composing; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; using Umbraco.Examine; using Umbraco.Web.Cache; using Umbraco.Web.Search; diff --git a/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs b/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs index d51ae4a114..d115bc7595 100644 --- a/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs +++ b/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs @@ -4,7 +4,7 @@ using System.Linq; using Newtonsoft.Json; using Umbraco.Composing; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Core.Sync { diff --git a/src/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs index 1571f63500..203e19fc6e 100644 --- a/src/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs @@ -1,8 +1,9 @@ using BenchmarkDotNet.Attributes; using System; using System.Linq; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; using Umbraco.Tests.Benchmarks.Config; namespace Umbraco.Tests.Benchmarks @@ -15,18 +16,17 @@ namespace Umbraco.Tests.Benchmarks [Benchmark(Baseline = true)] public void WithGetReferencingAssembliesCheck() { - var typeFinder1 = new TypeFinder(new NullLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); + var typeFinder1 = new TypeFinder(new NullLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); var found = typeFinder1.FindClassesOfType().Count(); } [Benchmark] public void WithoutGetReferencingAssembliesCheck() { - var typeFinder2 = new TypeFinder(new NullLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); + var typeFinder2 = new TypeFinder(new NullLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); typeFinder2.QueryWithReferencingAssemblies = false; var found = typeFinder2.FindClassesOfType().Count(); } - } } diff --git a/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj b/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj index 84ec535b9d..f0d1dff029 100644 --- a/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj +++ b/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj @@ -97,6 +97,9 @@ 0.11.3 + + 3.1.8 + \ No newline at end of file diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index cc01fa3528..c3f977e3c7 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Common { SettingsForTests = new SettingsForTests(); MainDom = new SimpleMainDom(); - _typeFinder = new TypeFinder(Mock.Of(), new DefaultUmbracoAssemblyProvider(entryAssembly), new VaryingRuntimeHash()); + _typeFinder = new TypeFinder(Mock.Of>(), new DefaultUmbracoAssemblyProvider(entryAssembly), new VaryingRuntimeHash()); } public ITypeFinder GetTypeFinder() => _typeFinder; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeFinderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeFinderTests.cs index bd9a3c7632..88fffd349d 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeFinderTests.cs @@ -1,11 +1,13 @@ using System; using System.Linq; using System.Reflection; +using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web.BackOffice.Trees; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.Composing { @@ -65,10 +67,11 @@ namespace Umbraco.Tests.Composing return new ProfilingLogger(logger, profiler); } - private static ILogger GetLogger() + // TODO: Is console logger the type of logger we want? + private static ILoggerFactory _factory = LoggerFactory.Create(builder => { builder.AddConsole(); }); + private static Microsoft.Extensions.Logging.ILogger GetLogger() { - // TODO: return some sort of actual logger. - return new NullLogger(); + return _factory.CreateLogger(); } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] diff --git a/src/Umbraco.Tests/Integration/ContentEventsTests.cs b/src/Umbraco.Tests/Integration/ContentEventsTests.cs index 1bedfed768..9a1321c20f 100644 --- a/src/Umbraco.Tests/Integration/ContentEventsTests.cs +++ b/src/Umbraco.Tests/Integration/ContentEventsTests.cs @@ -6,7 +6,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Web.Composing; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Sync; @@ -33,7 +33,7 @@ namespace Umbraco.Tests.Integration { base.SetUp(); - _h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of()); + _h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of()); _h1.BindEvents(true); _events = new List(); diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs index 338d7ff305..c472778f9f 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Xml.XPath; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; using Umbraco.Web.Models; diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs index 96f27a7051..7f8793b098 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs @@ -2,9 +2,9 @@ using System.IO; using System.Linq; using System.Xml; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Composing; diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs index f9e152bdb7..02510d8e88 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs @@ -5,12 +5,12 @@ using System.IO; using System.Linq; using System.Threading; using System.Xml.XPath; +using Microsoft.Extensions.Logging; using Examine; using Examine.Search; using Lucene.Net.Store; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs index 8a3d307507..c6680aa3e4 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs @@ -5,12 +5,12 @@ using System.IO; using System.Linq; using System.Text; using System.Xml; +using Microsoft.Extensions.Logging; using NPoco; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories; diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs index 20c32f2f6f..0a14a0bf68 100644 --- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs +++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 5c968f2f90..e48601c4e7 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -60,7 +60,7 @@ namespace Umbraco.Tests.TestHelpers public override IBackOfficeInfo GetBackOfficeInfo() => new AspNetBackOfficeInfo( SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()), - TestHelper.IOHelper, Mock.Of(), SettingsForTests.GenerateMockWebRoutingSettings()); + TestHelper.IOHelper, Mock.Of>(), SettingsForTests.GenerateMockWebRoutingSettings()); public override IHostingEnvironment GetHostingEnvironment() => new AspNetHostingEnvironment(SettingsForTests.DefaultHostingSettings); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 4fec590de1..852b0e2210 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -171,15 +171,16 @@ namespace Umbraco.Tests.Testing // FIXME: align to runtimes & components - don't redo everything here !!!! Yes this is getting painful var (logger, msLogger, profiler) = GetLoggers(Options.Logger); + var loggerFactoy = GetLoggerFactory(Options.Logger); var proflogger = new ProfilingLogger(logger, profiler); IOHelper = TestHelper.IOHelper; - TypeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); + TypeFinder = new TypeFinder(loggerFactoy.CreateLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); var appCaches = GetAppCaches(); var globalSettings = TestHelpers.SettingsForTests.DefaultGlobalSettings; var settings = TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings(); - IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, logger, settings); + IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, loggerFactoy.CreateLogger(), settings); IIpResolver ipResolver = new AspNetIpResolver(); UmbracoVersion = new UmbracoVersion(globalSettings); @@ -256,6 +257,29 @@ namespace Umbraco.Tests.Testing #region Compose + protected virtual ILoggerFactory GetLoggerFactory(UmbracoTestOptions.Logger option) + { + ILoggerFactory factory; + + switch (option) + { + case UmbracoTestOptions.Logger.Mock: + // TODO: Make factory return mock of ILogger + factory = Mock.Of(); + break; + case UmbracoTestOptions.Logger.Serilog: + factory = LoggerFactory.Create(builder => { builder.AddSerilog(); }); + break; + case UmbracoTestOptions.Logger.Console: + factory = LoggerFactory.Create(builder => { builder.AddConsole(); }); + break; + default: + throw new NotSupportedException($"Logger option {option} is not supported."); + } + + return factory; + } + protected virtual (ILogger, Microsoft.Extensions.Logging.ILogger, IProfiler) GetLoggers(UmbracoTestOptions.Logger option) { // TODO: Fix this, give the microsoft loggers a name diff --git a/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateExtensions.cs b/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateExtensions.cs index 7808c83295..77c07e85b2 100644 --- a/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateExtensions.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.PropertyEditors.ValueConverters; +using Microsoft.Extensions.Logging; namespace Umbraco.Extensions { diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 2a59a0fa95..2d2230dcc8 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -15,6 +15,7 @@ using Microsoft.Extensions.Logging; using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; +using Umbraco.Composing; using Umbraco.Configuration; using Umbraco.Core; using Umbraco.Core.Cache; @@ -247,10 +248,10 @@ namespace Umbraco.Extensions var globalSettings = configs.Global(); var umbracoVersion = new UmbracoVersion(globalSettings); - var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, configs.TypeFinder()); + var typeFinder = CreateTypeFinder(logger, Current.LoggerFactory, profiler, webHostEnvironment, entryAssembly, configs.TypeFinder()); var runtime = getRuntime( - configs, + configs, umbracoVersion, ioHelper, logger, @@ -267,12 +268,12 @@ namespace Umbraco.Extensions return services; } - private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, ITypeFinderSettings typeFinderSettings) + private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, ILoggerFactory loggerFactory, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, ITypeFinderSettings typeFinderSettings) { var runtimeHashPaths = new RuntimeHashPaths(); runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin"))); var runtimeHash = new RuntimeHash(new ProfilingLogger(logger, profiler), runtimeHashPaths); - return new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(entryAssembly), runtimeHash, new TypeFinderConfig(typeFinderSettings)); + return new TypeFinder(loggerFactory.CreateLogger(), new DefaultUmbracoAssemblyProvider(entryAssembly), runtimeHash, new TypeFinderConfig(typeFinderSettings)); } private static IRuntime GetCoreRuntime( @@ -294,7 +295,7 @@ namespace Umbraco.Extensions var mainDom = new MainDom(logger, mainDomLock); var coreRuntime = new CoreRuntime( - configs, + configs, umbracoVersion, ioHelper, logger, diff --git a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs index d72c64ebf9..66578f1517 100644 --- a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs +++ b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs @@ -3,7 +3,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Web { @@ -11,10 +11,10 @@ namespace Umbraco.Web { private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IWebRoutingSettings _webRoutingSettings; - public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IWebRoutingSettings webRoutingSettings) + public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IWebRoutingSettings webRoutingSettings) { _globalSettings = globalSettings; _ioHelper = ioHelper; diff --git a/src/Umbraco.Web/CdfLogger.cs b/src/Umbraco.Web/CdfLogger.cs index 0fe9c663bc..c0cf2129fc 100644 --- a/src/Umbraco.Web/CdfLogger.cs +++ b/src/Umbraco.Web/CdfLogger.cs @@ -1,5 +1,5 @@ using System; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Web.Composing; using ICdfLogger = ClientDependency.Core.Logging.ILogger; using ICoreLogger = Umbraco.Core.Logging.ILogger; @@ -11,7 +11,7 @@ namespace Umbraco.Web /// public class CdfLogger : ICdfLogger { - private readonly ICoreLogger _logger; + private readonly ILogger _logger; // Client Dependency doesn't know how to inject public CdfLogger(/*ICoreLogger logger*/) diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index b41a45ae2d..94a76ef850 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -247,7 +247,7 @@ namespace Umbraco.Web.Composing public static IShortStringHelper ShortStringHelper => Factory.GetInstance(); - public static ILogger Logger => Umbraco.Composing.Current.Logger; + public static Microsoft.Extensions.Logging.ILogger Logger => Umbraco.Composing.Current.Logger; public static ILoggerFactory LoggerFactory => Umbraco.Composing.Current.LoggerFactory; diff --git a/src/Umbraco.Web/ImageProcessorLogger.cs b/src/Umbraco.Web/ImageProcessorLogger.cs index bdbf95ed38..ad7a6ceaaf 100644 --- a/src/Umbraco.Web/ImageProcessorLogger.cs +++ b/src/Umbraco.Web/ImageProcessorLogger.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.CompilerServices; +using Microsoft.Extensions.Logging; using ImageProcessor.Common.Exceptions; using Umbraco.Web.Composing; -using Umbraco.Core.Logging; namespace Umbraco.Web { diff --git a/src/Umbraco.Web/Logging/OwinLogger.cs b/src/Umbraco.Web/Logging/OwinLogger.cs index afa4b42cab..7983ee36c7 100644 --- a/src/Umbraco.Web/Logging/OwinLogger.cs +++ b/src/Umbraco.Web/Logging/OwinLogger.cs @@ -1,6 +1,6 @@ using System; using System.Diagnostics; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Web.Logging { diff --git a/src/Umbraco.Web/Mvc/AdminTokenAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/AdminTokenAuthorizeAttribute.cs index 24aef4c370..25a2f958f8 100644 --- a/src/Umbraco.Web/Mvc/AdminTokenAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/AdminTokenAuthorizeAttribute.cs @@ -4,8 +4,8 @@ using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Mvc; +using Microsoft.Extensions.Logging; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Web.Composing; @@ -19,7 +19,7 @@ namespace Umbraco.Web.Mvc // see note in HttpInstallAuthorizeAttribute private readonly IUserService _userService; private readonly IRuntimeState _runtimeState; - private readonly ILogger _logger; + private readonly ILogger _logger; private IUserService UserService => _userService ?? Current.Services.UserService; diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index e9e05f40ef..af896ae243 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -4,9 +4,9 @@ using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Web.SessionState; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; using Umbraco.Core.Strings; using Umbraco.Web.Features; using Umbraco.Web.Models; diff --git a/src/Umbraco.Web/Security/AuthenticationOptionsExtensions.cs b/src/Umbraco.Web/Security/AuthenticationOptionsExtensions.cs index 660007917c..73156cec45 100644 --- a/src/Umbraco.Web/Security/AuthenticationOptionsExtensions.cs +++ b/src/Umbraco.Web/Security/AuthenticationOptionsExtensions.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; using Microsoft.Owin; using Microsoft.Owin.Security; using Umbraco.Core; diff --git a/src/Umbraco.Web/Security/MembershipHelper.cs b/src/Umbraco.Web/Security/MembershipHelper.cs index 0ad586616e..00758b2a65 100644 --- a/src/Umbraco.Web/Security/MembershipHelper.cs +++ b/src/Umbraco.Web/Security/MembershipHelper.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Security; +using Microsoft.Extensions.Logging; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Web.Models; using Umbraco.Web.PublishedCache; @@ -16,6 +16,7 @@ using Umbraco.Core.Strings; using Umbraco.Web.Editors; using Umbraco.Web.Security.Providers; using System.ComponentModel.DataAnnotations; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Web.Security { diff --git a/src/Umbraco.Web/Security/MembershipProviderBase.cs b/src/Umbraco.Web/Security/MembershipProviderBase.cs index 7e81008374..a62ef958c4 100644 --- a/src/Umbraco.Web/Security/MembershipProviderBase.cs +++ b/src/Umbraco.Web/Security/MembershipProviderBase.cs @@ -8,10 +8,10 @@ using System.Web; using System.Web.Hosting; using System.Web.Configuration; using System.Web.Security; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Web.Composing; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; using Umbraco.Core.Security; namespace Umbraco.Web.Security diff --git a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs index 81bd2b161d..57c0c23e33 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs @@ -5,10 +5,10 @@ using System.Linq; using System.Text; using System.Web.Configuration; using System.Web.Security; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; using Umbraco.Core.Models.Membership; using Umbraco.Net; using Umbraco.Core.Persistence.Querying; diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 3af09eb3e6..92f7826ac6 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -7,14 +7,13 @@ using System.Web; using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Runtime; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Web.Runtime; -using ILogger = Umbraco.Core.Logging.ILogger; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Umbraco.Web { @@ -38,10 +37,10 @@ namespace Umbraco.Web var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); var mainDomLock = appSettingMainDomLock == "SqlMainDomLock" || isWindows == false - ? (IMainDomLock)new SqlMainDomLock(logger, globalSettings, connectionStrings, dbProviderFactoryCreator, hostingEnvironment) - : new MainDomSemaphoreLock(logger, hostingEnvironment); + ? (IMainDomLock)new SqlMainDomLock(loggerFactory.CreateLogger(), loggerFactory, globalSettings, connectionStrings, dbProviderFactoryCreator, hostingEnvironment) + : new MainDomSemaphoreLock(loggerFactory.CreateLogger(), hostingEnvironment); - var mainDom = new MainDom(logger, mainDomLock); + var mainDom = new MainDom(loggerFactory.CreateLogger(), mainDomLock); var requestCache = new HttpRequestAppCache(() => HttpContext.Current != null ? HttpContext.Current.Items : null); var appCaches = new AppCaches( diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index ed5c2115d4..711d534d8e 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Web; using System.Web.Hosting; using Microsoft.Extensions.Logging; +using Serilog; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; @@ -20,7 +21,7 @@ using Umbraco.Web.AspNet; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; using Current = Umbraco.Web.Composing.Current; -using ILogger = Umbraco.Core.Logging.ILogger; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Umbraco.Web { @@ -31,6 +32,7 @@ namespace Umbraco.Web { private IRuntime _runtime; private IFactory _factory; + private ILoggerFactory _loggerFactory; protected UmbracoApplicationBase() { @@ -47,11 +49,25 @@ namespace Umbraco.Web Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.config"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.user.config")); var ioHelper = new IOHelper(hostingEnvironment); - var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); + + // TODO: Configure Serilog somewhere else + var loggerConfig = new LoggerConfiguration(); + loggerConfig + .MinimalConfiguration(hostingEnvironment, loggingConfiguration) + .ReadFromConfigFile(loggingConfiguration) + .ReadFromUserConfigFile(loggingConfiguration); + Log.Logger = loggerConfig.CreateLogger(); + + _loggerFactory = LoggerFactory.Create(builder => + { + builder.AddSerilog(); + }); + + var logger = _loggerFactory.CreateLogger(); var configs = configFactory.Create(); - var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, configFactory.WebRoutingSettings); + var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, _loggerFactory.CreateLogger(), configFactory.WebRoutingSettings); var profiler = GetWebProfiler(hostingEnvironment); Umbraco.Composing.Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler); Logger = logger; @@ -74,7 +90,7 @@ namespace Umbraco.Web return webProfiler; } - protected UmbracoApplicationBase(ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected UmbracoApplicationBase(Microsoft.Extensions.Logging.ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { if (!Umbraco.Composing.Current.IsInitialized) { @@ -83,7 +99,7 @@ namespace Umbraco.Web } } - protected ILogger Logger { get; } + protected Microsoft.Extensions.Logging.ILogger Logger { get; } /// /// Gets a @@ -104,7 +120,7 @@ namespace Umbraco.Web // global.asax (the app domain also monitors this, if it changes will do a full restart) runtimeHashPaths.AddFile(new FileInfo(hostingEnvironment.MapPathContentRoot("~/global.asax"))); var runtimeHash = new RuntimeHash(new ProfilingLogger(logger, profiler), runtimeHashPaths); - return new TypeFinder(Logger, new DefaultUmbracoAssemblyProvider( + return new TypeFinder(_loggerFactory.CreateLogger(), new DefaultUmbracoAssemblyProvider( // GetEntryAssembly was actually an exposed API by request of the aspnetcore team which works in aspnet core because a website // in that case is essentially an exe. However in netframework there is no entry assembly, things don't really work that way since // the process that is running the site is iisexpress, so this returns null. The best we can do is fallback to GetExecutingAssembly() diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 93b1acfbe4..d81bb61251 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Templates; using Umbraco.Core.Strings; using Umbraco.Core.Xml; using Umbraco.Web.Mvc; +using Microsoft.Extensions.Logging; namespace Umbraco.Web { diff --git a/src/Umbraco.Web/UmbracoHttpHandler.cs b/src/Umbraco.Web/UmbracoHttpHandler.cs index 042cc794b3..9a25c17298 100644 --- a/src/Umbraco.Web/UmbracoHttpHandler.cs +++ b/src/Umbraco.Web/UmbracoHttpHandler.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Security; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Umbraco.Web { diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index 66ae70be44..74b4190b16 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Web; using System.Web.Routing; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Security; using Umbraco.Core.Cache; @@ -9,7 +10,6 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Web.Composing; using Umbraco.Web.Routing; using Umbraco.Web.Security; diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 3dfd648667..7e4ac6c3d5 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -1,7 +1,7 @@ using System; using System.Web; +using Microsoft.Extensions.Logging; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Web.Composing; using Umbraco.Web.Routing; diff --git a/src/Umbraco.Web/UmbracoWebService.cs b/src/Umbraco.Web/UmbracoWebService.cs index dc7bf3f9e7..f71036c0ae 100644 --- a/src/Umbraco.Web/UmbracoWebService.cs +++ b/src/Umbraco.Web/UmbracoWebService.cs @@ -3,6 +3,7 @@ using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Web.Services; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; @@ -11,6 +12,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Security; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Umbraco.Web { diff --git a/src/Umbraco.Web/WebApi/Filters/AngularAntiForgeryHelper.cs b/src/Umbraco.Web/WebApi/Filters/AngularAntiForgeryHelper.cs index 717df89a7b..4b16e650da 100644 --- a/src/Umbraco.Web/WebApi/Filters/AngularAntiForgeryHelper.cs +++ b/src/Umbraco.Web/WebApi/Filters/AngularAntiForgeryHelper.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Web.Helpers; +using Microsoft.Extensions.Logging; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Web.Composing; namespace Umbraco.Web.WebApi.Filters diff --git a/src/Umbraco.Web/WebApi/Filters/FileUploadCleanupFilterAttribute.cs b/src/Umbraco.Web/WebApi/Filters/FileUploadCleanupFilterAttribute.cs index 1f944bad99..b12fc51ca6 100644 --- a/src/Umbraco.Web/WebApi/Filters/FileUploadCleanupFilterAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/FileUploadCleanupFilterAttribute.cs @@ -4,8 +4,8 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Web.Http.Filters; +using Microsoft.Extensions.Logging; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; diff --git a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs b/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs index 3803cdbab6..903e333846 100644 --- a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs +++ b/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs @@ -1,6 +1,6 @@ using System.Web.Http.ExceptionHandling; using Umbraco.Web.Composing; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Logging; namespace Umbraco.Web.WebApi {