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 |
|||
{ |
|||
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 JetBrains.Annotations; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Volo.Abp.Logging |
|||
{ |
|||
public class AbpInitLogEntry |
|||
{ |
|||
public LogLevel Level { get; } |
|||
|
|||
public string Message { get; } |
|||
|
|||
[CanBeNull] |
|||
public Exception Exception { get; } |
|||
|
|||
public AbpInitLogEntry( |
|||
LogLevel level, |
|||
string message, |
|||
Exception exception) |
|||
{ |
|||
Level = level; |
|||
Message = message; |
|||
Exception = exception; |
|||
} |
|||
public LogLevel LogLevel { get; set; } |
|||
|
|||
public EventId EventId { get; set; } |
|||
|
|||
public object State { get; set; } |
|||
|
|||
public Exception Exception { get; set; } |
|||
|
|||
public Func<object, Exception, string> Formatter { get; set; } |
|||
|
|||
public string Message => Formatter(State, Exception); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,16 +1,10 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Generic; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Volo.Abp.Logging |
|||
{ |
|||
public interface IInitLogger |
|||
public interface IInitLogger<out T> : ILogger<T> |
|||
{ |
|||
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