From ed30cd1800ac53d44dce748fa6812dfe38ef8df5 Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 21 Sep 2020 13:09:48 +0200 Subject: [PATCH] Remove ILogger and its classes implementing it --- .../Composing/ComponentCollection.cs | 1 + .../Logging/DebugDiagnosticsLogger.cs | 86 ----------- src/Umbraco.Core/Logging/ILogger.cs | 93 ----------- .../Logging/Serilog/SerilogLogger.cs | 145 ------------------ .../Components/ComponentTests.cs | 2 - .../Runtimes/CoreRuntimeTests.cs | 1 - src/Umbraco.Web/CdfLogger.cs | 47 ------ src/Umbraco.Web/Umbraco.Web.csproj | 1 - 8 files changed, 1 insertion(+), 375 deletions(-) delete mode 100644 src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs delete mode 100644 src/Umbraco.Core/Logging/ILogger.cs delete mode 100644 src/Umbraco.Infrastructure/Logging/Serilog/SerilogLogger.cs delete mode 100644 src/Umbraco.Web/CdfLogger.cs diff --git a/src/Umbraco.Core/Composing/ComponentCollection.cs b/src/Umbraco.Core/Composing/ComponentCollection.cs index 752fbf8614..509962599c 100644 --- a/src/Umbraco.Core/Composing/ComponentCollection.cs +++ b/src/Umbraco.Core/Composing/ComponentCollection.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using Umbraco.Core.Logging; namespace Umbraco.Core.Composing diff --git a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs b/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs deleted file mode 100644 index 2492dee672..0000000000 --- a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; - -namespace Umbraco.Core.Logging -{ - /// - /// Implements on top of . - /// - public class DebugDiagnosticsLogger : ILogger - { - private readonly IMessageTemplates _messageTemplates; - - public DebugDiagnosticsLogger(IMessageTemplates messageTemplates) - { - _messageTemplates = messageTemplates; - } - - public bool IsEnabled(Type reporting, LogLevel level) - => true; - - /// - public void Fatal(Type reporting, Exception exception) - { - System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName); - } - - /// - public void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, typeof(T).FullName); - } - - /// - public void LogCritical(string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(messageTemplate, propertyValues); - } - - /// - public void LogError(Type reporting, Exception exception) - { - System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName); - } - - /// - public void LogError(Exception exception, string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, typeof(T).FullName); - } - - /// - public void LogError(string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(messageTemplate, propertyValues); - } - - /// - public void LogWarning(string message, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message, propertyValues), typeof(T).FullName); - } - - /// - public void LogWarning(Exception exception, string message, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message + Environment.NewLine + exception, propertyValues), typeof(T).FullName); - } - - /// - public void LogInformation(string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName); - } - - /// - public void LogDebug(string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName); - } - - /// - public void LogTrace(string messageTemplate, params object[] propertyValues) - { - System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName); - } - } -} diff --git a/src/Umbraco.Core/Logging/ILogger.cs b/src/Umbraco.Core/Logging/ILogger.cs deleted file mode 100644 index da590c6bba..0000000000 --- a/src/Umbraco.Core/Logging/ILogger.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; - -namespace Umbraco.Core.Logging -{ - - public interface ILogger : ILogger { } - - /// - /// Defines the logging service. - /// - /// - /// Message templates in logging methods follow the Message Templates specification - /// available at https://messagetemplates.org/ in order to support structured logging. - /// Implementations must ensure that they support these templates. Note that the - /// specification includes support for traditional C# numeric placeholders. - /// For instance, "Processed {Input} in {Time}ms." - /// - public interface ILogger - { - /// - /// Determines if logging is enabled at a specified level, for a reporting type. - /// - /// The reporting type. - /// The level. - bool IsEnabled(Type reporting, LogLevel level); - - /// - /// Logs a fatal message with an exception. - /// - /// An exception. - /// A message template. - /// Property values. - void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues); - - /// - /// Logs a fatal message. - /// - /// A message template. - /// Property values. - void LogCritical(string messageTemplate, params object[] propertyValues); - - /// - /// Logs an error message with an exception. - /// - /// An exception. - /// A message template. - /// Property values. - void LogError(Exception exception, string messageTemplate, params object[] propertyValues); - - /// - /// Logs an error message. - /// - /// A message template. - /// Property values. - void LogError(string messageTemplate, params object[] propertyValues); - - /// - /// Logs a warning message. - /// - /// A message template. - /// Property values. - void LogWarning(string messageTemplate, params object[] propertyValues); - - /// - /// Logs a warning message with an exception. - /// - /// An exception. - /// A message template. - /// Property values. - void LogWarning(Exception exception, string messageTemplate, params object[] propertyValues); - - /// - /// Logs a info message. - /// - /// A message template. - /// Property values. - void LogInformation(string messageTemplate, params object[] propertyValues); - - /// - /// Logs a debug message. - /// - /// A message template. - /// Property values. - void LogDebug(string messageTemplate, params object[] propertyValues); - - /// - /// Logs a verbose message. - /// - /// A message template. - /// Property values. - void LogTrace(string messageTemplate, params object[] propertyValues); - } -} diff --git a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogLogger.cs b/src/Umbraco.Infrastructure/Logging/Serilog/SerilogLogger.cs deleted file mode 100644 index 95bf17cb23..0000000000 --- a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogLogger.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.IO; -using Org.BouncyCastle.Asn1.X509.Qualified; -using Serilog; -using Serilog.Events; -using Umbraco.Core.Hosting; - -namespace Umbraco.Core.Logging.Serilog -{ - - /// - /// Implements on top of Serilog. - /// - public class SerilogLogger : ILogger, IDisposable - { - public global::Serilog.ILogger SerilogLog { get; } - - /// - /// Initialize a new instance of the class with a configuration file. - /// - /// - public SerilogLogger(FileInfo logConfigFile) - { - SerilogLog = new LoggerConfiguration() - .ReadFrom.AppSettings(filePath: logConfigFile.FullName) - .CreateLogger(); - } - - public SerilogLogger(LoggerConfiguration logConfig) - { - //Configure Serilog static global logger with config passed in - SerilogLog = logConfig.CreateLogger(); - } - - /// - /// Creates a logger with some pre-defined configuration and remainder from config file - /// - /// Used by UmbracoApplicationBase to get its logger. - public static SerilogLogger CreateWithDefaultConfiguration(IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration) - { - var loggerConfig = new LoggerConfiguration(); - loggerConfig - .MinimalConfiguration(hostingEnvironment, loggingConfiguration) - .ReadFromConfigFile(loggingConfiguration) - .ReadFromUserConfigFile(loggingConfiguration); - - return new SerilogLogger(loggerConfig); - } - - /// - /// Gets a contextualized logger. - /// - private global::Serilog.ILogger LoggerFor(Type reporting) - => SerilogLog.ForContext(reporting); - - /// - /// Maps Umbraco's log level to Serilog's. - /// - private LogEventLevel MapLevel(LogLevel level) - { - switch (level) - { - case LogLevel.Debug: - return LogEventLevel.Debug; - case LogLevel.Error: - return LogEventLevel.Error; - case LogLevel.Fatal: - return LogEventLevel.Fatal; - case LogLevel.Information: - return LogEventLevel.Information; - case LogLevel.Verbose: - return LogEventLevel.Verbose; - case LogLevel.Warning: - return LogEventLevel.Warning; - } - - throw new NotSupportedException($"LogLevel \"{level}\" is not supported."); - } - - /// - public bool IsEnabled(Type reporting, LogLevel level) - => LoggerFor(reporting).IsEnabled(MapLevel(level)); - - /// - public void LogCritical(string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Fatal(messageTemplate, propertyValues); - } - - /// - public void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues) - { - var logger = LoggerFor(typeof(T)); - logger.Fatal(exception, messageTemplate, propertyValues); - } - - /// - public void LogError(string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Error(messageTemplate, propertyValues); - } - - /// - public void LogError(Exception exception, string messageTemplate, params object[] propertyValues) - { - var logger = LoggerFor(typeof(T)); - logger.Error(exception, messageTemplate, propertyValues); - } - - /// - public void LogWarning(string message, params object[] propertyValues) - { - LoggerFor(typeof(T)).Warning(message, propertyValues); - } - - /// - public void LogWarning(Exception exception, string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Warning(exception, messageTemplate, propertyValues); - } - - /// - public void LogInformation(string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Information(messageTemplate, propertyValues); - } - - /// - public void LogDebug(string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Debug(messageTemplate, propertyValues); - } - - /// - public void LogTrace(string messageTemplate, params object[] propertyValues) - { - LoggerFor(typeof(T)).Verbose(messageTemplate, propertyValues); - } - - public void Dispose() - { - SerilogLog.DisposeIfDisposable(); - } - } -} diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index bfc3066590..9e209f633f 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -46,7 +46,6 @@ namespace Umbraco.Tests.Components var p = new ScopeProvider(f, fs, Microsoft.Extensions.Options.Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, typeFinder, NoAppCache.Instance); mock.Setup(x => x.GetInstance(typeof (ILogger))).Returns(logger); - mock.Setup(x => x.GetInstance(typeof (Umbraco.Core.Logging.ILogger))).Returns(Mock.Of()); mock.Setup(x => x.GetInstance(typeof(ILoggerFactory))).Returns(loggerFactory); mock.Setup(x => x.GetInstance(typeof (IProfilingLogger))).Returns(new ProfilingLogger(logger, Mock.Of())); mock.Setup(x => x.GetInstance(typeof (IUmbracoDatabaseFactory))).Returns(f); @@ -99,7 +98,6 @@ namespace Umbraco.Tests.Components if (type == typeof(Composer5)) return new Composer5(); if (type == typeof(Component5)) return new Component5(new SomeResource()); if (type == typeof(IProfilingLogger)) return new ProfilingLogger(Mock.Of(), Mock.Of()); - if (type == typeof(Core.Logging.ILogger)) return Mock.Of(); throw new NotSupportedException(type.FullName); }); }); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 6b7bea2bca..36ad2998ac 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -70,7 +70,6 @@ namespace Umbraco.Tests.Runtimes Assert.IsTrue(TestComponent.Ctored); Assert.IsNotNull(TestComponent.ProfilingLogger); Assert.IsInstanceOf(TestComponent.ProfilingLogger); - Assert.IsInstanceOf>(((ProfilingLogger) TestComponent.ProfilingLogger).Logger); // note: components are NOT disposed after boot diff --git a/src/Umbraco.Web/CdfLogger.cs b/src/Umbraco.Web/CdfLogger.cs deleted file mode 100644 index c0cf2129fc..0000000000 --- a/src/Umbraco.Web/CdfLogger.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using Umbraco.Web.Composing; -using ICdfLogger = ClientDependency.Core.Logging.ILogger; -using ICoreLogger = Umbraco.Core.Logging.ILogger; - -namespace Umbraco.Web -{ - /// - /// A logger for ClientDependency - /// - public class CdfLogger : ICdfLogger - { - private readonly ILogger _logger; - - // Client Dependency doesn't know how to inject - public CdfLogger(/*ICoreLogger logger*/) - { - _logger = Current.Logger; - } - - public void Debug(string msg) - { - _logger.LogDebug(msg); - } - - public void Info(string msg) - { - _logger.LogInformation(msg); - } - - public void Warn(string msg) - { - _logger.LogWarning(msg); - } - - public void Error(string msg, Exception ex) - { - _logger.LogError(ex, msg); - } - - public void Fatal(string msg, Exception ex) - { - _logger.LogError(ex, msg); - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index ffc5da3b21..3dcacb9ee0 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -322,7 +322,6 @@ -