Remove ILogger and its classes implementing it
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements <see cref="ILogger"/> on top of <see cref="System.Diagnostics"/>.
|
||||
/// </summary>
|
||||
public class DebugDiagnosticsLogger<T> : ILogger
|
||||
{
|
||||
private readonly IMessageTemplates _messageTemplates;
|
||||
|
||||
public DebugDiagnosticsLogger(IMessageTemplates messageTemplates)
|
||||
{
|
||||
_messageTemplates = messageTemplates;
|
||||
}
|
||||
|
||||
public bool IsEnabled(Type reporting, LogLevel level)
|
||||
=> true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogCritical(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogError(Type reporting, Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogError(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogError(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogWarning(string message, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message, propertyValues), typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogWarning(Exception exception, string message, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message + Environment.NewLine + exception, propertyValues), typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogInformation(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogDebug(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogTrace(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), typeof(T).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
|
||||
public interface ILogger : ILogger<object> { }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the logging service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Message templates in logging methods follow the Message Templates specification
|
||||
/// available at https://messagetemplates.org/ in order to support structured logging.</para>
|
||||
/// <para>Implementations must ensure that they support these templates. Note that the
|
||||
/// specification includes support for traditional C# numeric placeholders.</para>
|
||||
/// <para>For instance, "Processed {Input} in {Time}ms."</para>
|
||||
/// </remarks>
|
||||
public interface ILogger<out T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines if logging is enabled at a specified level, for a reporting type.
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="level">The level.</param>
|
||||
bool IsEnabled(Type reporting, LogLevel level);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message with an exception.
|
||||
/// </summary>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogCritical(string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs an error message with an exception.
|
||||
/// </summary>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogError(Exception exception, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs an error message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogError(string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a warning message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogWarning(string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a warning message with an exception.
|
||||
/// </summary>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogWarning(Exception exception, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a info message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogInformation(string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a debug message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogDebug(string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a verbose message.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">A message template.</param>
|
||||
/// <param name="propertyValues">Property values.</param>
|
||||
void LogTrace(string messageTemplate, params object[] propertyValues);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
///<summary>
|
||||
/// Implements <see cref="ILogger"/> on top of Serilog.
|
||||
///</summary>
|
||||
public class SerilogLogger<T> : ILogger, IDisposable
|
||||
{
|
||||
public global::Serilog.ILogger SerilogLog { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of the <see cref="SerilogLogger<T>"/> class with a configuration file.
|
||||
/// </summary>
|
||||
/// <param name="logConfigFile"></param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a logger with some pre-defined configuration and remainder from config file
|
||||
/// </summary>
|
||||
/// <remarks>Used by UmbracoApplicationBase to get its logger.</remarks>
|
||||
public static SerilogLogger<T> CreateWithDefaultConfiguration(IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration)
|
||||
{
|
||||
var loggerConfig = new LoggerConfiguration();
|
||||
loggerConfig
|
||||
.MinimalConfiguration(hostingEnvironment, loggingConfiguration)
|
||||
.ReadFromConfigFile(loggingConfiguration)
|
||||
.ReadFromUserConfigFile(loggingConfiguration);
|
||||
|
||||
return new SerilogLogger<T>(loggerConfig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a contextualized logger.
|
||||
/// </summary>
|
||||
private global::Serilog.ILogger LoggerFor(Type reporting)
|
||||
=> SerilogLog.ForContext(reporting);
|
||||
|
||||
/// <summary>
|
||||
/// Maps Umbraco's log level to Serilog's.
|
||||
/// </summary>
|
||||
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.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsEnabled(Type reporting, LogLevel level)
|
||||
=> LoggerFor(reporting).IsEnabled(MapLevel(level));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogCritical(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Fatal(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogCritical(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
var logger = LoggerFor(typeof(T));
|
||||
logger.Fatal(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogError(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Error(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogError(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
var logger = LoggerFor(typeof(T));
|
||||
logger.Error(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogWarning(string message, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Warning(message, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogWarning(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Warning(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogInformation(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Information(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogDebug(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Debug(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LogTrace(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
LoggerFor(typeof(T)).Verbose(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
SerilogLog.DisposeIfDisposable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,6 @@ namespace Umbraco.Tests.Components
|
||||
var p = new ScopeProvider(f, fs, Microsoft.Extensions.Options.Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger<ScopeProvider>(), 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<Umbraco.Core.Logging.ILogger>());
|
||||
mock.Setup(x => x.GetInstance(typeof(ILoggerFactory))).Returns(loggerFactory);
|
||||
mock.Setup(x => x.GetInstance(typeof (IProfilingLogger))).Returns(new ProfilingLogger(logger, Mock.Of<IProfiler>()));
|
||||
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<ILogger>(), Mock.Of<IProfiler>());
|
||||
if (type == typeof(Core.Logging.ILogger)) return Mock.Of<Core.Logging.ILogger>();
|
||||
throw new NotSupportedException(type.FullName);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,7 +70,6 @@ namespace Umbraco.Tests.Runtimes
|
||||
Assert.IsTrue(TestComponent.Ctored);
|
||||
Assert.IsNotNull(TestComponent.ProfilingLogger);
|
||||
Assert.IsInstanceOf<ProfilingLogger>(TestComponent.ProfilingLogger);
|
||||
Assert.IsInstanceOf<DebugDiagnosticsLogger<object>>(((ProfilingLogger) TestComponent.ProfilingLogger).Logger);
|
||||
|
||||
// note: components are NOT disposed after boot
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// A logger for ClientDependency
|
||||
/// </summary>
|
||||
public class CdfLogger : ICdfLogger
|
||||
{
|
||||
private readonly ILogger<object> _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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,6 @@
|
||||
<Compile Include="Mvc\ControllerFactoryExtensions.cs" />
|
||||
<Compile Include="Mvc\IRenderMvcController.cs" />
|
||||
<Compile Include="Mvc\SurfaceRouteHandler.cs" />
|
||||
<Compile Include="CdfLogger.cs" />
|
||||
<Compile Include="Controllers\UmbLoginController.cs" />
|
||||
<Compile Include="UrlHelperExtensions.cs" />
|
||||
<Compile Include="UrlHelperRenderExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user