Skip to content

Commit a4d877f

Browse files
committed
- more pattern matching
1 parent f0b5ad4 commit a4d877f

21 files changed

+102
-45
lines changed

src/log4net/Appender/AdoNetAppender.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,13 @@ protected virtual void SendBuffer(IDbTransaction? dbTran, LoggingEvent[] events)
452452
{
453453
if (!string.IsNullOrWhiteSpace(CommandText))
454454
{
455-
using IDbCommand dbCmd = Connection!.CreateCommand();
456-
// Set the command string
455+
using IDbCommand dbCmd = Connection.EnsureNotNull().CreateCommand();
457456
dbCmd.CommandText = CommandText;
458-
459-
// Set the command type
460457
dbCmd.CommandType = CommandType;
461-
// Send buffer using the prepared command object
462458
if (dbTran is not null)
463459
{
464460
dbCmd.Transaction = dbTran;
465461
}
466-
467462
try
468463
{
469464
// prepare the command, which is significantly faster
@@ -476,7 +471,6 @@ protected virtual void SendBuffer(IDbTransaction? dbTran, LoggingEvent[] events)
476471
// rethrow exception in transaction mode, cuz now transaction is in failed state
477472
throw;
478473
}
479-
480474
// ignore prepare exceptions as they can happen without affecting actual logging, eg on npgsql
481475
}
482476

@@ -581,7 +575,7 @@ protected virtual IDbConnection CreateConnection(Type connectionType, string con
581575
/// <returns>A connection string used to connect to the database.</returns>
582576
protected virtual string ResolveConnectionString(out string connectionStringContext)
583577
{
584-
if (ConnectionString is string { Length: > 0 })
578+
if (ConnectionString is { Length: > 0 })
585579
{
586580
connectionStringContext = "ConnectionString";
587581
return ConnectionString;
@@ -601,7 +595,7 @@ protected virtual string ResolveConnectionString(out string connectionStringCont
601595
}
602596
}
603597

604-
if (AppSettingsKey is string { Length: > 0 })
598+
if (AppSettingsKey is { Length: > 0 })
605599
{
606600
connectionStringContext = "AppSettingsKey";
607601
string? appSettingsConnectionString = SystemInfo.GetAppSetting(AppSettingsKey);

src/log4net/Core/DefaultRepositorySelector.cs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -678,24 +678,19 @@ private static void ConfigureRepository(Assembly assembly, ILoggerRepository rep
678678
/// </exception>
679679
private static void LoadPlugins(Assembly assembly, ILoggerRepository repository)
680680
{
681-
repository.EnsureNotNull();
682-
683681
// Look for the PluginAttribute on the assembly
684-
PluginAttribute[] configAttributes = Attribute.GetCustomAttributes(assembly.EnsureNotNull(), typeof(PluginAttribute), false)
682+
PluginAttribute[] configAttributes = Attribute.GetCustomAttributes(assembly, typeof(PluginAttribute), false)
685683
.EnsureIs<PluginAttribute[]>();
686-
if (configAttributes.Length > 0)
684+
foreach (PluginAttribute configAttr in configAttributes)
687685
{
688-
foreach (PluginAttribute configAttr in configAttributes)
686+
try
689687
{
690-
try
691-
{
692-
// Create the plugin and add it to the repository
693-
repository.PluginMap.Add(configAttr.CreatePlugin());
694-
}
695-
catch (Exception ex)
696-
{
697-
LogLog.Error(declaringType, $"Failed to create plugin. Attribute [{configAttr}]", ex);
698-
}
688+
// Create the plugin and add it to the repository
689+
repository.PluginMap.Add(configAttr.CreatePlugin());
690+
}
691+
catch (Exception ex)
692+
{
693+
LogLog.Error(declaringType, $"Failed to create plugin. Attribute [{configAttr}]", ex);
699694
}
700695
}
701696
}
@@ -712,24 +707,19 @@ private static void LoadPlugins(Assembly assembly, ILoggerRepository repository)
712707
/// </exception>
713708
private void LoadAliases(Assembly assembly, ILoggerRepository repository)
714709
{
715-
assembly.EnsureNotNull();
716-
repository.EnsureNotNull();
717-
718710
// Look for the AliasRepositoryAttribute on the assembly
719-
AliasRepositoryAttribute[] configAttributes = Attribute.GetCustomAttributes(assembly, typeof(AliasRepositoryAttribute), false)
711+
AliasRepositoryAttribute[] configAttributes = Attribute
712+
.GetCustomAttributes(assembly, typeof(AliasRepositoryAttribute), false)
720713
.EnsureIs<AliasRepositoryAttribute[]>();
721-
if (configAttributes.Length > 0)
714+
foreach (AliasRepositoryAttribute configAttr in configAttributes)
722715
{
723-
foreach (AliasRepositoryAttribute configAttr in configAttributes)
716+
try
724717
{
725-
try
726-
{
727-
AliasRepository(configAttr.Name, repository);
728-
}
729-
catch (Exception ex)
730-
{
731-
LogLog.Error(declaringType, $"Failed to alias repository [{configAttr.Name}]", ex);
732-
}
718+
AliasRepository(configAttr.Name, repository);
719+
}
720+
catch (Exception ex)
721+
{
722+
LogLog.Error(declaringType, $"Failed to alias repository [{configAttr.Name}]", ex);
733723
}
734724
}
735725
}

src/log4net/Diagnostics/CodeAnalysis/AllowNullAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
namespace System.Diagnostics.CodeAnalysis;
2224

src/log4net/Diagnostics/CodeAnalysis/CallerArgumentExpressionAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CallerArgumentExpressionAttribute.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
namespace System.Runtime.CompilerServices;
2224

src/log4net/Diagnostics/CodeAnalysis/CompilerFeatureRequiredAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CompilerFeatureRequiredAttribute.cs
21+
2022
#if !NET7_0_OR_GREATER
2123
namespace System.Runtime.CompilerServices;
2224

src/log4net/Diagnostics/CodeAnalysis/DisallowNullAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
namespace System.Diagnostics.CodeAnalysis;
2224

src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
namespace System.Diagnostics.CodeAnalysis;
2224

src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnIfAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
namespace System.Diagnostics.CodeAnalysis;
2224

src/log4net/Diagnostics/CodeAnalysis/IsExternalInit.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
#endregion
1919

20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs
21+
2022
#if !NET6_0_OR_GREATER
2123
using System.ComponentModel;
2224

src/log4net/Diagnostics/CodeAnalysis/MaybeNullAttribute.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
#if !NET6_0_OR_GREATER
1+
#region Apache License
2+
//
3+
// Licensed to the Apache Software Foundation (ASF) under one or more
4+
// contributor license agreements. See the NOTICE file distributed with
5+
// this work for additional information regarding copyright ownership.
6+
// The ASF licenses this file to you under the Apache License, Version 2.0
7+
// (the "License"); you may not use this file except in compliance with
8+
// the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
#endregion
19+
20+
// inspired by https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
21+
22+
#if !NET6_0_OR_GREATER
223
namespace System.Diagnostics.CodeAnalysis;
324

425
/// <summary>

0 commit comments

Comments
 (0)