Skip to content

Commit 3aed7cb

Browse files
committed
fixed remaining warnings
1 parent fb9235d commit 3aed7cb

File tree

122 files changed

+1101
-1708
lines changed

Some content is hidden

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

122 files changed

+1101
-1708
lines changed

src/log4net.Tests/Appender/AdoNet/Log4NetCommand.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace log4net.Tests.Appender.AdoNet;
2626

27-
public class Log4NetCommand : IDbCommand
27+
internal sealed class Log4NetCommand : IDbCommand
2828
{
2929
public Log4NetCommand()
3030
{
@@ -48,10 +48,7 @@ public int ExecuteNonQuery()
4848

4949
public int ExecuteNonQueryCount { get; private set; }
5050

51-
public IDbDataParameter CreateParameter()
52-
{
53-
return new Log4NetParameter();
54-
}
51+
public IDbDataParameter CreateParameter() => new Log4NetParameter();
5552

5653
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
5754
public string? CommandText { get; set; }
@@ -68,25 +65,13 @@ public void Prepare()
6865

6966
public static Log4NetCommand? MostRecentInstance { get; private set; }
7067

71-
public void Cancel()
72-
{
73-
throw new NotImplementedException();
74-
}
68+
public void Cancel() => throw new NotImplementedException();
7569

76-
public IDataReader ExecuteReader()
77-
{
78-
throw new NotImplementedException();
79-
}
70+
public IDataReader ExecuteReader() => throw new NotImplementedException();
8071

81-
public IDataReader ExecuteReader(CommandBehavior behavior)
82-
{
83-
throw new NotImplementedException();
84-
}
72+
public IDataReader ExecuteReader(CommandBehavior behavior) => throw new NotImplementedException();
8573

86-
public object ExecuteScalar()
87-
{
88-
throw new NotImplementedException();
89-
}
74+
public object ExecuteScalar() => throw new NotImplementedException();
9075

9176
public IDbConnection? Connection
9277
{

src/log4net.Tests/Appender/AdoNet/Log4NetConnection.cs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,35 @@
2424

2525
namespace log4net.Tests.Appender.AdoNet;
2626

27-
public class Log4NetConnection : IDbConnection
27+
internal sealed class Log4NetConnection : IDbConnection
2828
{
2929
private bool _open;
3030

31-
public Log4NetConnection()
32-
{
33-
MostRecentInstance = this;
34-
}
31+
public Log4NetConnection() => MostRecentInstance = this;
3532

36-
public void Close()
37-
{
38-
_open = false;
39-
}
33+
public void Close() => _open = false;
4034

4135
public ConnectionState State => _open ? ConnectionState.Open : ConnectionState.Closed;
4236

4337
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
4438
public string? ConnectionString { get; set; }
4539
#pragma warning restore CS8766
4640

47-
public IDbTransaction BeginTransaction()
48-
{
49-
return new Log4NetTransaction();
50-
}
41+
public IDbTransaction BeginTransaction() => new Log4NetTransaction();
5142

52-
public IDbCommand CreateCommand()
53-
{
54-
return new Log4NetCommand();
55-
}
43+
public IDbCommand CreateCommand() => new Log4NetCommand();
5644

57-
public void Open()
58-
{
59-
_open = true;
60-
}
45+
public void Open() => _open = true;
6146

6247
public static Log4NetConnection? MostRecentInstance { get; private set; }
6348

64-
public IDbTransaction BeginTransaction(IsolationLevel il)
65-
{
66-
throw new NotImplementedException();
67-
}
49+
public IDbTransaction BeginTransaction(IsolationLevel il) => throw new NotImplementedException();
6850

69-
public void ChangeDatabase(string databaseName)
70-
{
71-
throw new NotImplementedException();
72-
}
51+
public void ChangeDatabase(string databaseName) => throw new NotImplementedException();
7352

7453
public int ConnectionTimeout => throw new NotImplementedException();
7554

7655
public string Database => throw new NotImplementedException();
7756

78-
public void Dispose()
79-
{
80-
throw new NotImplementedException();
81-
}
57+
public void Dispose() => throw new NotImplementedException();
8258
}

src/log4net.Tests/Appender/AdoNet/Log4NetParameterCollection.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace log4net.Tests.Appender.AdoNet;
2828

29-
public class Log4NetParameterCollection : CollectionBase, IDataParameterCollection
29+
internal sealed class Log4NetParameterCollection : CollectionBase, IDataParameterCollection
3030
{
3131
private readonly Dictionary<string, int> _parameterNameToIndex = new(StringComparer.Ordinal);
3232

@@ -55,13 +55,7 @@ public object this[string parameterName]
5555
set => InnerList[IndexOf(parameterName)] = value;
5656
}
5757

58-
public void RemoveAt(string parameterName)
59-
{
60-
throw new NotImplementedException();
61-
}
58+
public void RemoveAt(string parameterName) => throw new NotImplementedException();
6259

63-
public bool Contains(string parameterName)
64-
{
65-
throw new NotImplementedException();
66-
}
60+
public bool Contains(string parameterName) => throw new NotImplementedException();
6761
}

src/log4net.Tests/Appender/AdoNet/Log4NetTransaction.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace log4net.Tests.Appender.AdoNet;
2626

27-
public class Log4NetTransaction : IDbTransaction
27+
internal sealed class Log4NetTransaction : IDbTransaction
2828
{
2929
public void Commit()
3030
{
@@ -40,8 +40,5 @@ public void Rollback()
4040

4141
public IsolationLevel IsolationLevel => throw new NotImplementedException();
4242

43-
public void Dispose()
44-
{
45-
throw new NotImplementedException();
46-
}
43+
public void Dispose() => throw new NotImplementedException();
4744
}

src/log4net.Tests/Appender/CountingAppender.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,11 @@ public class CountingAppender : AppenderSkeleton
4444
/// <summary>
4545
/// Reset the counter to zero
4646
/// </summary>
47-
public void ResetCounter()
48-
{
49-
Counter = 0;
50-
}
47+
public void ResetCounter() => Counter = 0;
5148

5249
/// <summary>
5350
/// Registers how many times the method has been called.
5451
/// </summary>
55-
/// <param name="logEvent">The logging event.</param>
56-
protected override void Append(LoggingEvent logEvent)
57-
{
58-
Counter++;
59-
}
60-
}
52+
/// <param name="loggingEvent">The logging event.</param>
53+
protected override void Append(LoggingEvent loggingEvent) => Counter++;
54+
}

src/log4net.Tests/Appender/EventRaisingAppender.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,9 @@ namespace log4net.Tests.Appender;
2727
/// <summary>
2828
/// Provides data for the <see cref="EventRaisingAppender.LoggingEventAppended"/> event.
2929
/// </summary>
30-
/// <seealso cref="System.EventArgs" />
31-
public class LoggingEventEventArgs : EventArgs
30+
public class LoggingEventEventArgs(LoggingEvent loggingEvent) : EventArgs
3231
{
33-
public LoggingEvent LoggingEvent { get; private set; }
34-
35-
public LoggingEventEventArgs(LoggingEvent loggingEvent)
36-
{
37-
if (loggingEvent is null)
38-
{
39-
throw new ArgumentNullException(nameof(loggingEvent));
40-
}
41-
42-
LoggingEvent = loggingEvent;
43-
}
32+
public LoggingEvent LoggingEvent { get; } = loggingEvent ?? throw new ArgumentNullException(nameof(loggingEvent));
4433
}
4534

4635
/// <summary>
@@ -55,18 +44,13 @@ public class EventRaisingAppender : log4net.Appender.IAppender
5544
public event EventHandler<LoggingEventEventArgs>? LoggingEventAppended;
5645

5746
protected void OnLoggingEventAppended(LoggingEventEventArgs e)
58-
{
59-
LoggingEventAppended?.Invoke(this, e);
60-
}
47+
=> LoggingEventAppended?.Invoke(this, e);
6148

6249
public void Close()
63-
{
64-
}
50+
{ }
6551

6652
public void DoAppend(LoggingEvent loggingEvent)
67-
{
68-
OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
69-
}
53+
=> OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
7054

7155
public string Name { get; set; } = string.Empty;
72-
}
56+
}

src/log4net.Tests/Context/LogicalThreadContextTest.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ namespace log4net.Tests.Context;
4141
public class LogicalThreadContextTest
4242
{
4343
[TearDown]
44-
public void TearDown()
45-
{
46-
Utils.RemovePropertyFromAllContexts();
47-
}
44+
public void TearDown() => Utils.RemovePropertyFromAllContexts();
4845

4946
[Test]
5047
public void TestLogicalThreadPropertiesPatternBasicGetSet()
@@ -100,7 +97,7 @@ public async Task TestLogicalThreadPropertiesPatternAsyncAwait()
10097
Assert.That(stringAppender.GetString(), Is.EqualTo(testValueForCurrentContext), "Test logical thread properties value set");
10198
stringAppender.Reset();
10299

103-
var strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkProperties(x.ToString())));
100+
string[] strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkProperties(x.ToString()))).ConfigureAwait(false);
104101

105102
// strings should be ["00AA0BB0", "01AA1BB1", "02AA2BB2", ...]
106103
for (int i = 0; i < strings.Length; i++)
@@ -274,7 +271,7 @@ public async Task TestLogicalThreadStackPatternAsyncAwait()
274271
Assert.That(stringAppender.GetString(), Is.EqualTo(testValueForCurrentContext), "Test logical thread stack value set");
275272
stringAppender.Reset();
276273

277-
strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkStack(x.ToString())));
274+
strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkStack(x.ToString()))).ConfigureAwait(false);
278275
}
279276

280277
// strings should be ["Outer 0 AOuter 0 AOuter 0Outer 0 BOuter 0 B Outer 0", ...]
@@ -305,9 +302,9 @@ static async Task<string> SomeWorkProperties(string propertyName)
305302
LogicalThreadContext.Properties[Utils.PropertyKey] = propertyName;
306303
log.Info("TestMessage");
307304

308-
await MoreWorkProperties(log, "A");
305+
await MoreWorkProperties(log, "A").ConfigureAwait(false);
309306
log.Info("TestMessage");
310-
await MoreWorkProperties(log, "B");
307+
await MoreWorkProperties(log, "B").ConfigureAwait(false);
311308
log.Info("TestMessage");
312309
return stringAppender.GetString();
313310
}
@@ -316,7 +313,7 @@ static async Task MoreWorkProperties(ILog log, string propertyName)
316313
{
317314
LogicalThreadContext.Properties[Utils.PropertyKey] = propertyName;
318315
log.Info("TestMessage");
319-
await Task.Delay(1);
316+
await Task.Delay(1).ConfigureAwait(false);
320317
log.Info("TestMessage");
321318
}
322319

@@ -338,9 +335,9 @@ private static async Task<string> SomeWorkStack(string stackName)
338335
Assert.That(stringAppender.GetString(), Is.EqualTo(string.Format("Outer {0}", stackName)), "Test logical thread stack value set");
339336
stringAppender.Reset();
340337

341-
await MoreWorkStack(log, "A");
338+
await MoreWorkStack(log, "A").ConfigureAwait(false);
342339
log.Info("TestMessage");
343-
await MoreWorkStack(log, "B");
340+
await MoreWorkStack(log, "B").ConfigureAwait(false);
344341
log.Info("TestMessage");
345342
}
346343

@@ -352,7 +349,7 @@ static async Task MoreWorkStack(ILog log, string stackName)
352349
using (LogicalThreadContext.Stacks[Utils.PropertyKey].Push(stackName))
353350
{
354351
log.Info("TestMessage");
355-
await Task.Delay(1);
352+
await Task.Delay(1).ConfigureAwait(false);
356353
log.Info("TestMessage");
357354
}
358355
}

src/log4net.Tests/Core/EvaluatorTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace log4net.Tests.Core;
3131

3232
[TestFixture]
33+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")]
3334
public class EvaluatorTest
3435
{
3536
private BufferingForwardingAppender _bufferingForwardingAppender = new();

src/log4net.Tests/Core/LoggingEventTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private static readonly DateTime _localTime
3838

3939
[Test]
4040
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2300:Do not use insecure deserializer BinaryFormatter")]
41+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2301:Do not use insecure deserializer BinaryFormatter")]
4142
public void SerializeDeserialize_BinaryFormatter()
4243
{
4344
Utils.InconclusiveOnMono();
@@ -88,6 +89,7 @@ public void SerializeDeserialize_BinaryFormatter()
8889
/// </summary>
8990
[Test]
9091
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2300:Do not use insecure deserializer BinaryFormatter")]
92+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2301:Do not use insecure deserializer BinaryFormatter")]
9193
public void DeserializeV2()
9294
{
9395
Utils.InconclusiveOnMono();

src/log4net.Tests/Core/StringFormatTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
namespace log4net.Tests.Core;
3232

3333
[TestFixture]
34+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")]
3435
public class StringFormatTest
3536
{
3637
private CultureInfo? _currentCulture;

0 commit comments

Comments
 (0)