-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWimaLoggerExtensions.cs
52 lines (45 loc) · 1.93 KB
/
WimaLoggerExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;
using CM = Common.Logging;
namespace Wima.Log
{
public static class WimaLoggerExtensions
{
public static ILoggingBuilder AddWimaLogger(this ILoggingBuilder builder)
{
//builder.AddConfiguration();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, WimaLoggerProvider>());
//LoggerProviderOptions.RegisterProviderOptions<WimaLoggerConfiguration, WimaLoggerProvider>(builder.Services);
return builder;
}
public static ILoggingBuilder AddWimaLogger(this ILoggingBuilder builder, Action<WimaLoggerConfiguration> configure)
{
builder.AddWimaLogger();
builder.Services.Configure(configure);
return builder;
}
public static CM.LogLevel Map2CommonLogLevel(this LogLevel level) => level switch
{
LogLevel.Trace => CM.LogLevel.Trace,
LogLevel.Debug => CM.LogLevel.Debug,
LogLevel.Warning => CM.LogLevel.Warn,
LogLevel.Information => CM.LogLevel.Info,
LogLevel.Error => CM.LogLevel.Error,
LogLevel.Critical => CM.LogLevel.Fatal,
_ => CM.LogLevel.Off,
};
public static LogLevel Map2MsLogLevel(this CM.LogLevel level) => level switch
{
CM.LogLevel.Trace => LogLevel.Trace,
CM.LogLevel.Debug => LogLevel.Debug,
CM.LogLevel.Warn => LogLevel.Warning,
CM.LogLevel.Info => LogLevel.Information,
CM.LogLevel.Error => LogLevel.Error,
CM.LogLevel.Fatal => LogLevel.Critical,
CM.LogLevel.All => LogLevel.Information,
_ => LogLevel.None,
};
}
}