11using System ;
2+ using System . Collections . Generic ;
23using Microsoft . Extensions . Logging ;
4+ using Microsoft . Extensions . Logging . Internal ;
35
46namespace NHibernate . Example . Web . Infrastructure
57{
@@ -12,85 +14,40 @@ public NHibernateToMicrosoftLogger(ILogger msLogger)
1214 _msLogger = msLogger ?? throw new ArgumentNullException ( nameof ( msLogger ) ) ;
1315 }
1416
15- public void Fatal ( Exception exception , string format , params object [ ] args )
17+ private static readonly Dictionary < InternalLogLevel , LogLevel > MapLevels = new Dictionary < InternalLogLevel , LogLevel >
1618 {
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+ } ;
5426
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- }
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 ) ;
6932
70- public void Error ( string message , Exception ex )
33+ public void Log ( InternalLogLevel logLevel , object state , Exception exception )
7134 {
72- throw new NotImplementedException ( ) ;
73- }
35+ if ( state is InternalLogEvent logEvent )
36+ {
37+ state = new FormattedLogValues ( logEvent . Format , logEvent . Args ) ;
38+ }
7439
75- public void Warn ( string message , Exception ex )
76- {
77- throw new NotImplementedException ( ) ;
40+ _msLogger . Log ( MapLevels [ logLevel ] , 0 , state , exception , MessageFormatter ) ;
7841 }
7942
80- public void Info ( string message , Exception ex )
43+ public bool IsEnabled ( InternalLogLevel logLevel )
8144 {
82- throw new NotImplementedException ( ) ;
45+ return _msLogger . IsEnabled ( MapLevels [ logLevel ] ) ;
8346 }
8447
85- public void Debug ( string message , Exception ex )
48+ private static string MessageFormatter ( object state , Exception error )
8649 {
87- throw new NotImplementedException ( ) ;
50+ return state . ToString ( ) ;
8851 }
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 ) ;
9552 }
9653}
0 commit comments