Skip to content

Commit f432b14

Browse files
committed
Further simplify IInternalLogger2 by moving properties to extension methods.
1 parent 4919d6a commit f432b14

File tree

141 files changed

+445
-471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+445
-471
lines changed

src/NHibernate.Example.Web/Infrastructure/NHibernateToMicrosoftLogger.cs

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public NHibernateToMicrosoftLogger(ILogger msLogger)
2424
{ InternalLogLevel.None, LogLevel.None },
2525
};
2626

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);
32-
3327
public void Log(InternalLogLevel logLevel, object state, Exception exception)
3428
{
3529
if (state is InternalLogEvent logEvent)

src/NHibernate/AdoNet/AbstractBatcher.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public DbCommand Generate(CommandType type, SqlString sqlString, SqlType[] param
7373

7474
var cmd = _factory.ConnectionProvider.Driver.GenerateCommand(type, sql, parameterTypes);
7575
LogOpenPreparedCommand();
76-
if (Log.IsDebugEnabled)
76+
if (Log.IsDebugEnabled())
7777
{
7878
Log.Debug("Building an DbCommand object for the SqlString: {0}", sql);
7979
}
@@ -122,7 +122,7 @@ public virtual DbCommand PrepareBatchCommand(CommandType type, SqlString sql, Sq
122122
{
123123
if (sql.Equals(_batchCommandSql) && ArrayHelper.ArrayEquals(parameterTypes, _batchCommandParameterTypes))
124124
{
125-
if (Log.IsDebugEnabled)
125+
if (Log.IsDebugEnabled())
126126
{
127127
Log.Debug("reusing command {0}", _batchCommand.CommandText);
128128
}
@@ -190,7 +190,7 @@ public int ExecuteNonQuery(DbCommand cmd)
190190
LogCommand(cmd);
191191
Prepare(cmd);
192192
Stopwatch duration = null;
193-
if (Log.IsDebugEnabled)
193+
if (Log.IsDebugEnabled())
194194
duration = Stopwatch.StartNew();
195195
try
196196
{
@@ -204,7 +204,7 @@ public int ExecuteNonQuery(DbCommand cmd)
204204
}
205205
finally
206206
{
207-
if (Log.IsDebugEnabled && duration != null)
207+
if (Log.IsDebugEnabled() && duration != null)
208208
Log.Debug("ExecuteNonQuery took {0} ms", duration.ElapsedMilliseconds);
209209
}
210210
}
@@ -215,7 +215,7 @@ public virtual DbDataReader ExecuteReader(DbCommand cmd)
215215
LogCommand(cmd);
216216
Prepare(cmd);
217217
Stopwatch duration = null;
218-
if (Log.IsDebugEnabled)
218+
if (Log.IsDebugEnabled())
219219
duration = Stopwatch.StartNew();
220220
DbDataReader reader = null;
221221
try
@@ -230,7 +230,7 @@ public virtual DbDataReader ExecuteReader(DbCommand cmd)
230230
}
231231
finally
232232
{
233-
if (Log.IsDebugEnabled && duration != null && reader != null)
233+
if (Log.IsDebugEnabled() && duration != null && reader != null)
234234
{
235235
Log.Debug("ExecuteReader took {0} ms", duration.ElapsedMilliseconds);
236236
_readersDuration[reader] = duration;
@@ -388,7 +388,7 @@ private Stopwatch GetReaderStopwatch(DbDataReader reader)
388388

389389
private static void LogDuration(Stopwatch duration)
390390
{
391-
if (!Log.IsDebugEnabled || duration == null) return;
391+
if (!Log.IsDebugEnabled() || duration == null) return;
392392

393393
Log.Debug("DataReader was closed after {0} ms", duration.ElapsedMilliseconds);
394394
}
@@ -415,11 +415,11 @@ public void ExecuteBatch()
415415
protected void ExecuteBatchWithTiming(DbCommand ps)
416416
{
417417
Stopwatch duration = null;
418-
if (Log.IsDebugEnabled)
418+
if (Log.IsDebugEnabled())
419419
duration = Stopwatch.StartNew();
420420
var countBeforeExecutingBatch = CountOfStatementsInCurrentBatch;
421421
DoExecuteBatch(ps);
422-
if (Log.IsDebugEnabled && duration != null)
422+
if (Log.IsDebugEnabled() && duration != null)
423423
Log.Debug("ExecuteBatch for {0} statements took {1} ms",
424424
countBeforeExecutingBatch,
425425
duration.ElapsedMilliseconds);
@@ -478,7 +478,7 @@ protected void LogCommand(DbCommand command)
478478

479479
private void LogOpenPreparedCommand()
480480
{
481-
if (Log.IsDebugEnabled)
481+
if (Log.IsDebugEnabled())
482482
{
483483
int currentOpenCommandCount = Interlocked.Increment(ref _openCommandCount);
484484
Log.Debug("Opened new DbCommand, open DbCommands: {0}", currentOpenCommandCount);
@@ -492,7 +492,7 @@ private void LogOpenPreparedCommand()
492492

493493
private void LogClosePreparedCommand()
494494
{
495-
if (Log.IsDebugEnabled)
495+
if (Log.IsDebugEnabled())
496496
{
497497
int currentOpenCommandCount = Interlocked.Decrement(ref _openCommandCount);
498498
Log.Debug("Closed DbCommand, open DbCommands: {0}", currentOpenCommandCount);
@@ -506,7 +506,7 @@ private void LogClosePreparedCommand()
506506

507507
private static void LogOpenReader()
508508
{
509-
if (Log.IsDebugEnabled)
509+
if (Log.IsDebugEnabled())
510510
{
511511
int currentOpenReaderCount = Interlocked.Increment(ref _openReaderCount);
512512
Log.Debug("Opened DbDataReader, open DbDataReaders: {0}", currentOpenReaderCount);
@@ -515,7 +515,7 @@ private static void LogOpenReader()
515515

516516
private static void LogCloseReader()
517517
{
518-
if (Log.IsDebugEnabled)
518+
if (Log.IsDebugEnabled())
519519
{
520520
int currentOpenReaderCount = Interlocked.Decrement(ref _openReaderCount);
521521
Log.Debug("Closed DbDataReader, open DbDataReaders :{0}", currentOpenReaderCount);

src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void AddToBatch(IExpectation expectation)
4545
Driver.AdjustCommand(batchUpdate);
4646
string lineWithParameters = null;
4747
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
48-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
48+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
4949
{
5050
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
5151
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -55,7 +55,7 @@ public override void AddToBatch(IExpectation expectation)
5555
.Append(":")
5656
.AppendLine(lineWithParameters);
5757
}
58-
if (Log.IsDebugEnabled)
58+
if (Log.IsDebugEnabled())
5959
{
6060
Log.Debug("Adding to batch:{0}", lineWithParameters);
6161
}

src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void AddToBatch(IExpectation expectation)
3838
_totalExpectedRowsAffected += expectation.ExpectedRowCount;
3939
string lineWithParameters = null;
4040
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
41-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
41+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
4242
{
4343
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(CurrentCommand);
4444
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -48,7 +48,7 @@ public override void AddToBatch(IExpectation expectation)
4848
.Append(":")
4949
.AppendLine(lineWithParameters);
5050
}
51-
if (Log.IsDebugEnabled)
51+
if (Log.IsDebugEnabled())
5252
{
5353
Log.Debug("Adding to batch:{0}", lineWithParameters);
5454
}

src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void AddToBatch(IExpectation expectation)
4747
Driver.AdjustCommand(batchUpdate);
4848
string lineWithParameters = null;
4949
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
50-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
50+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
5151
{
5252
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
5353
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -57,7 +57,7 @@ public override void AddToBatch(IExpectation expectation)
5757
.Append(":")
5858
.AppendLine(lineWithParameters);
5959
}
60-
if (Log.IsDebugEnabled)
60+
if (Log.IsDebugEnabled())
6161
{
6262
Log.Debug("Adding to batch:{0}", lineWithParameters);
6363
}
@@ -109,7 +109,7 @@ private SqlClientSqlCommandSet CreateConfiguredBatch()
109109
}
110110
catch (Exception e)
111111
{
112-
if (Log.IsWarnEnabled)
112+
if (Log.IsWarnEnabled())
113113
{
114114
Log.Warn(e, e.ToString());
115115
}

src/NHibernate/AdoNet/Util/SqlStatementLogger.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SqlStatementLogger(bool logToStdout, bool formatSql)
3030

3131
public bool IsDebugEnabled
3232
{
33-
get { return Logger.IsDebugEnabled; }
33+
get { return Logger.IsDebugEnabled(); }
3434
}
3535

3636
/// <summary> Log a DbCommand. </summary>
@@ -39,7 +39,7 @@ public bool IsDebugEnabled
3939
/// <param name="style">The requested formatting style. </param>
4040
public virtual void LogCommand(string message, DbCommand command, FormatStyle style)
4141
{
42-
if (!Logger.IsDebugEnabled && !LogToStdout || string.IsNullOrEmpty(command.CommandText))
42+
if (!Logger.IsDebugEnabled() && !LogToStdout || string.IsNullOrEmpty(command.CommandText))
4343
{
4444
return;
4545
}

src/NHibernate/Async/AdoNet/AbstractBatcher.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public virtual async Task<DbCommand> PrepareBatchCommandAsync(CommandType type,
7272
cancellationToken.ThrowIfCancellationRequested();
7373
if (sql.Equals(_batchCommandSql) && ArrayHelper.ArrayEquals(parameterTypes, _batchCommandParameterTypes))
7474
{
75-
if (Log.IsDebugEnabled)
75+
if (Log.IsDebugEnabled())
7676
{
7777
Log.Debug("reusing command {0}", _batchCommand.CommandText);
7878
}
@@ -117,7 +117,7 @@ public async Task<int> ExecuteNonQueryAsync(DbCommand cmd, CancellationToken can
117117
LogCommand(cmd);
118118
await (PrepareAsync(cmd, cancellationToken)).ConfigureAwait(false);
119119
Stopwatch duration = null;
120-
if (Log.IsDebugEnabled)
120+
if (Log.IsDebugEnabled())
121121
duration = Stopwatch.StartNew();
122122
try
123123
{
@@ -131,7 +131,7 @@ public async Task<int> ExecuteNonQueryAsync(DbCommand cmd, CancellationToken can
131131
}
132132
finally
133133
{
134-
if (Log.IsDebugEnabled && duration != null)
134+
if (Log.IsDebugEnabled() && duration != null)
135135
Log.Debug("ExecuteNonQuery took {0} ms", duration.ElapsedMilliseconds);
136136
}
137137
}
@@ -143,7 +143,7 @@ public virtual async Task<DbDataReader> ExecuteReaderAsync(DbCommand cmd, Cancel
143143
LogCommand(cmd);
144144
await (PrepareAsync(cmd, cancellationToken)).ConfigureAwait(false);
145145
Stopwatch duration = null;
146-
if (Log.IsDebugEnabled)
146+
if (Log.IsDebugEnabled())
147147
duration = Stopwatch.StartNew();
148148
DbDataReader reader = null;
149149
try
@@ -158,7 +158,7 @@ public virtual async Task<DbDataReader> ExecuteReaderAsync(DbCommand cmd, Cancel
158158
}
159159
finally
160160
{
161-
if (Log.IsDebugEnabled && duration != null && reader != null)
161+
if (Log.IsDebugEnabled() && duration != null && reader != null)
162162
{
163163
Log.Debug("ExecuteReader took {0} ms", duration.ElapsedMilliseconds);
164164
_readersDuration[reader] = duration;
@@ -219,11 +219,11 @@ protected async Task ExecuteBatchWithTimingAsync(DbCommand ps, CancellationToken
219219
{
220220
cancellationToken.ThrowIfCancellationRequested();
221221
Stopwatch duration = null;
222-
if (Log.IsDebugEnabled)
222+
if (Log.IsDebugEnabled())
223223
duration = Stopwatch.StartNew();
224224
var countBeforeExecutingBatch = CountOfStatementsInCurrentBatch;
225225
await (DoExecuteBatchAsync(ps, cancellationToken)).ConfigureAwait(false);
226-
if (Log.IsDebugEnabled && duration != null)
226+
if (Log.IsDebugEnabled() && duration != null)
227227
Log.Debug("ExecuteBatch for {0} statements took {1} ms",
228228
countBeforeExecutingBatch,
229229
duration.ElapsedMilliseconds);

src/NHibernate/Async/AdoNet/MySqlClientBatchingBatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override async Task AddToBatchAsync(IExpectation expectation, Cancellatio
3030
Driver.AdjustCommand(batchUpdate);
3131
string lineWithParameters = null;
3232
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
33-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
33+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
3434
{
3535
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
3636
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -40,7 +40,7 @@ public override async Task AddToBatchAsync(IExpectation expectation, Cancellatio
4040
.Append(":")
4141
.AppendLine(lineWithParameters);
4242
}
43-
if (Log.IsDebugEnabled)
43+
if (Log.IsDebugEnabled())
4444
{
4545
Log.Debug("Adding to batch:{0}", lineWithParameters);
4646
}

src/NHibernate/Async/AdoNet/OracleDataClientBatchingBatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override Task AddToBatchAsync(IExpectation expectation, CancellationToken
3434
_totalExpectedRowsAffected += expectation.ExpectedRowCount;
3535
string lineWithParameters = null;
3636
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
37-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
37+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
3838
{
3939
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(CurrentCommand);
4040
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -44,7 +44,7 @@ public override Task AddToBatchAsync(IExpectation expectation, CancellationToken
4444
.Append(":")
4545
.AppendLine(lineWithParameters);
4646
}
47-
if (Log.IsDebugEnabled)
47+
if (Log.IsDebugEnabled())
4848
{
4949
Log.Debug("Adding to batch:{0}", lineWithParameters);
5050
}

src/NHibernate/Async/AdoNet/SqlClientBatchingBatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override Task AddToBatchAsync(IExpectation expectation, CancellationToken
3535
Driver.AdjustCommand(batchUpdate);
3636
string lineWithParameters = null;
3737
var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
38-
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
38+
if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
3939
{
4040
lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
4141
var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
@@ -45,7 +45,7 @@ public override Task AddToBatchAsync(IExpectation expectation, CancellationToken
4545
.Append(":")
4646
.AppendLine(lineWithParameters);
4747
}
48-
if (Log.IsDebugEnabled)
48+
if (Log.IsDebugEnabled())
4949
{
5050
Log.Debug("Adding to batch:{0}", lineWithParameters);
5151
}

src/NHibernate/Async/Cache/NonstrictReadWriteCache.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class NonstrictReadWriteCache : ICacheConcurrencyStrategy
2525
public async Task<object> GetAsync(CacheKey key, long txTimestamp, CancellationToken cancellationToken)
2626
{
2727
cancellationToken.ThrowIfCancellationRequested();
28-
if (log.IsDebugEnabled)
28+
if (log.IsDebugEnabled())
2929
{
3030
log.Debug("Cache lookup: {0}", key);
3131
}
@@ -57,13 +57,13 @@ public async Task<bool> PutAsync(CacheKey key, object value, long txTimestamp, o
5757

5858
if (minimalPut && await (cache.GetAsync(key, cancellationToken)).ConfigureAwait(false) != null)
5959
{
60-
if (log.IsDebugEnabled)
60+
if (log.IsDebugEnabled())
6161
{
6262
log.Debug("item already cached: {0}", key);
6363
}
6464
return false;
6565
}
66-
if (log.IsDebugEnabled)
66+
if (log.IsDebugEnabled())
6767
{
6868
log.Debug("Caching: {0}", key);
6969
}
@@ -98,7 +98,7 @@ public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
9898
}
9999
try
100100
{
101-
if (log.IsDebugEnabled)
101+
if (log.IsDebugEnabled())
102102
{
103103
log.Debug("Removing: {0}", key);
104104
}
@@ -118,7 +118,7 @@ public Task ClearAsync(CancellationToken cancellationToken)
118118
}
119119
try
120120
{
121-
if (log.IsDebugEnabled)
121+
if (log.IsDebugEnabled())
122122
{
123123
log.Debug("Clearing");
124124
}
@@ -141,7 +141,7 @@ public Task EvictAsync(CacheKey key, CancellationToken cancellationToken)
141141
}
142142
try
143143
{
144-
if (log.IsDebugEnabled)
144+
if (log.IsDebugEnabled())
145145
{
146146
log.Debug("Invalidating: {0}", key);
147147
}
@@ -174,7 +174,7 @@ public Task ReleaseAsync(CacheKey key, ISoftLock @lock, CancellationToken cancel
174174
}
175175
try
176176
{
177-
if (log.IsDebugEnabled)
177+
if (log.IsDebugEnabled())
178178
{
179179
log.Debug("Invalidating (again): {0}", key);
180180
}

0 commit comments

Comments
 (0)