mirror of https://github.com/abpframework/abp.git
13 changed files with 92 additions and 68 deletions
@ -1,12 +1,13 @@ |
|||||
using Volo.Abp.Logging; |
using Microsoft.Extensions.Logging; |
||||
|
using Volo.Abp.Logging; |
||||
|
|
||||
namespace Microsoft.Extensions.DependencyInjection |
namespace Microsoft.Extensions.DependencyInjection |
||||
{ |
{ |
||||
public static class ServiceCollectionLoggingExtensions |
public static class ServiceCollectionLoggingExtensions |
||||
{ |
{ |
||||
public static IInitLogger GetInitLogger(this IServiceCollection services) |
public static ILogger<T> GetInitLogger<T>(this IServiceCollection services) |
||||
{ |
{ |
||||
return services.GetSingletonInstance<IInitLogger>(); |
return services.GetSingletonInstance<IInitLoggerFactory>().Create<T>(); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,26 +1,20 @@ |
|||||
using System; |
using System; |
||||
using JetBrains.Annotations; |
|
||||
using Microsoft.Extensions.Logging; |
using Microsoft.Extensions.Logging; |
||||
|
|
||||
namespace Volo.Abp.Logging |
namespace Volo.Abp.Logging |
||||
{ |
{ |
||||
public class AbpInitLogEntry |
public class AbpInitLogEntry |
||||
{ |
{ |
||||
public LogLevel Level { get; } |
public LogLevel LogLevel { get; set; } |
||||
|
|
||||
public string Message { get; } |
public EventId EventId { get; set; } |
||||
|
|
||||
[CanBeNull] |
public object State { get; set; } |
||||
public Exception Exception { get; } |
|
||||
|
public Exception Exception { get; set; } |
||||
public AbpInitLogEntry( |
|
||||
LogLevel level, |
public Func<object, Exception, string> Formatter { get; set; } |
||||
string message, |
|
||||
Exception exception) |
public string Message => Formatter(State, Exception); |
||||
{ |
|
||||
Level = level; |
|
||||
Message = message; |
|
||||
Exception = exception; |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,16 +1,10 @@ |
|||||
using System; |
using System.Collections.Generic; |
||||
using System.Collections.Generic; |
|
||||
using Microsoft.Extensions.Logging; |
using Microsoft.Extensions.Logging; |
||||
|
|
||||
namespace Volo.Abp.Logging |
namespace Volo.Abp.Logging |
||||
{ |
{ |
||||
public interface IInitLogger |
public interface IInitLogger<out T> : ILogger<T> |
||||
{ |
{ |
||||
public List<AbpInitLogEntry> Entries { get; } |
public List<AbpInitLogEntry> Entries { get; } |
||||
|
|
||||
void Log( |
|
||||
LogLevel logLevel, |
|
||||
string message, |
|
||||
Exception exception = null); |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.Logging |
||||
|
{ |
||||
|
public interface IInitLoggerFactory |
||||
|
{ |
||||
|
IInitLogger<T> Create<T>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Logging |
||||
|
{ |
||||
|
public class InitLoggerFactory : IInitLoggerFactory |
||||
|
{ |
||||
|
private readonly Dictionary<Type, object> _cache = new Dictionary<Type, object>(); |
||||
|
|
||||
|
public virtual IInitLogger<T> Create<T>() |
||||
|
{ |
||||
|
return (IInitLogger<T>)_cache.GetOrAdd(typeof(T), () => new DefaultInitLogger<T>());; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue