1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using Microsoft . Extensions . Logging ;
4
+ using Microsoft . Extensions . Logging . Internal ;
3
5
4
6
namespace NHibernate . Example . Web . Infrastructure
5
7
{
@@ -12,85 +14,35 @@ public NHibernateToMicrosoftLogger(ILogger msLogger)
12
14
_msLogger = msLogger ?? throw new ArgumentNullException ( nameof ( msLogger ) ) ;
13
15
}
14
16
15
- public void Fatal ( Exception exception , string format , params object [ ] args )
17
+ private static readonly Dictionary < InternalLogLevel , LogLevel > MapLevels = new Dictionary < InternalLogLevel , LogLevel >
16
18
{
17
- _msLogger . LogCritical ( exception , format , args ) ;
18
- }
19
-
20
- public void Fatal ( string format , params object [ ] args )
21
- {
22
- _msLogger . LogCritical ( format , args ) ;
23
- }
24
-
25
- public void Error ( Exception exception , string format , params object [ ] args )
26
- {
27
- _msLogger . LogError ( exception , format , args ) ;
28
- }
29
-
30
- public void Error ( string format , params object [ ] args )
31
- {
32
- _msLogger . LogError ( format , args ) ;
33
- }
34
-
35
- public void Warn ( Exception exception , string format , params object [ ] args )
36
- {
37
- _msLogger . LogWarning ( exception , format , args ) ;
38
- }
39
-
40
- public void Warn ( string format , params object [ ] args )
41
- {
42
- _msLogger . LogWarning ( format , args ) ;
43
- }
44
-
45
- public void Info ( Exception exception , string format , params object [ ] args )
46
- {
47
- _msLogger . LogInformation ( exception , format , args ) ;
48
- }
49
-
50
- public void Info ( string format , params object [ ] args )
51
- {
52
- _msLogger . LogInformation ( format , args ) ;
53
- }
19
+ { InternalLogLevel . Trace , LogLevel . Trace } ,
20
+ { InternalLogLevel . Debug , LogLevel . Debug } ,
21
+ { InternalLogLevel . Warn , LogLevel . Warning } ,
22
+ { InternalLogLevel . Error , LogLevel . Error } ,
23
+ { InternalLogLevel . Fatal , LogLevel . Critical } ,
24
+ { InternalLogLevel . None , LogLevel . None } ,
25
+ } ;
54
26
55
- public void Debug ( Exception exception , string format , params object [ ] args )
56
- {
57
- _msLogger . LogDebug ( exception , format , args ) ;
58
- }
59
-
60
- public void Debug ( string format , params object [ ] args )
61
- {
62
- _msLogger . LogDebug ( format , args ) ;
63
- }
64
-
65
- public void Fatal ( string message , Exception ex )
66
- {
67
- throw new NotImplementedException ( ) ;
68
- }
69
-
70
- public void Error ( string message , Exception ex )
71
- {
72
- throw new NotImplementedException ( ) ;
73
- }
27
+ public bool IsDebugEnabled => _msLogger . IsEnabled ( LogLevel . Debug ) ;
28
+ public bool IsInfoEnabled => _msLogger . IsEnabled ( LogLevel . Information ) ;
29
+ public bool IsWarnEnabled => _msLogger . IsEnabled ( LogLevel . Warning ) ;
30
+ public bool IsErrorEnabled => _msLogger . IsEnabled ( LogLevel . Error ) ;
31
+ public bool IsFatalEnabled => _msLogger . IsEnabled ( LogLevel . Critical ) ;
74
32
75
- public void Warn ( string message , Exception ex )
33
+ public void Log ( InternalLogLevel logLevel , InternalLogValues state , Exception exception )
76
34
{
77
- throw new NotImplementedException ( ) ;
35
+ _msLogger . Log ( MapLevels [ logLevel ] , 0 , new FormattedLogValues ( state . Format , state . Args ) , exception , MessageFormatter ) ;
78
36
}
79
37
80
- public void Info ( string message , Exception ex )
38
+ public bool IsEnabled ( InternalLogLevel logLevel )
81
39
{
82
- throw new NotImplementedException ( ) ;
40
+ return _msLogger . IsEnabled ( MapLevels [ logLevel ] ) ;
83
41
}
84
42
85
- public void Debug ( string message , Exception ex )
43
+ private static string MessageFormatter ( object state , Exception error )
86
44
{
87
- throw new NotImplementedException ( ) ;
45
+ return state . ToString ( ) ;
88
46
}
89
-
90
- public bool IsErrorEnabled => _msLogger . IsEnabled ( LogLevel . Error ) ;
91
- public bool IsFatalEnabled => _msLogger . IsEnabled ( LogLevel . Critical ) ;
92
- public bool IsDebugEnabled => _msLogger . IsEnabled ( LogLevel . Debug ) ;
93
- public bool IsInfoEnabled => _msLogger . IsEnabled ( LogLevel . Information ) ;
94
- public bool IsWarnEnabled => _msLogger . IsEnabled ( LogLevel . Warning ) ;
95
47
}
96
48
}
0 commit comments