You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by fr...@apache.org on 2024/10/23 09:56:00 UTC
(logging-log4net) branch Feature/NetAnalyzers updated: fixed remaining warnings
This is an automated email from the ASF dual-hosted git repository.
freeandnil pushed a commit to branch Feature/NetAnalyzers
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/Feature/NetAnalyzers by this push:
new 3aed7cbb fixed remaining warnings
3aed7cbb is described below
commit 3aed7cbb34d073f037d80f1c3939f3c623f0a6f1
Author: Jan Friedrich <fr...@apache.org>
AuthorDate: Wed Oct 23 11:55:38 2024 +0200
fixed remaining warnings
---
.../Appender/AdoNet/Log4NetCommand.cs | 27 +-
.../Appender/AdoNet/Log4NetConnection.cs | 42 +--
.../Appender/AdoNet/Log4NetParameterCollection.cs | 12 +-
.../Appender/AdoNet/Log4NetTransaction.cs | 7 +-
src/log4net.Tests/Appender/CountingAppender.cs | 14 +-
src/log4net.Tests/Appender/EventRaisingAppender.cs | 28 +-
.../Context/LogicalThreadContextTest.cs | 21 +-
src/log4net.Tests/Core/EvaluatorTest.cs | 1 +
src/log4net.Tests/Core/LoggingEventTest.cs | 2 +
src/log4net.Tests/Core/StringFormatTest.cs | 1 +
.../DateFormatter/AbsoluteTimeDateFormatterTest.cs | 27 +-
src/log4net.Tests/Layout/PatternLayoutTest.cs | 22 +-
src/log4net.Tests/Layout/XmlLayoutTest.cs | 64 ++--
.../Util/EnvironmentPatternConverterTest.cs | 12 +-
src/log4net.Tests/Util/LogLogTest.cs | 14 +-
src/log4net.Tests/Util/PropertiesDictionaryTest.cs | 3 +-
.../Util/RandomStringPatternConverterTest.cs | 19 +-
src/log4net/Appender/AnsiColorTerminalAppender.cs | 2 +-
src/log4net/Appender/AppenderSkeleton.cs | 70 ++---
src/log4net/Appender/AspNetTraceAppender.cs | 4 +-
src/log4net/Appender/BufferingAppenderSkeleton.cs | 17 +-
.../Appender/BufferingForwardingAppender.cs | 9 +-
src/log4net/Appender/ColoredConsoleAppender.cs | 3 +-
src/log4net/Appender/ConsoleAppender.cs | 2 +-
src/log4net/Appender/DebugAppender.cs | 2 +-
src/log4net/Appender/EventLogAppender.cs | 2 +-
src/log4net/Appender/FileAppender.cs | 25 +-
src/log4net/Appender/ForwardingAppender.cs | 43 +--
src/log4net/Appender/IAppender.cs | 2 +-
src/log4net/Appender/LocalSyslogAppender.cs | 2 +-
.../Appender/ManagedColoredConsoleAppender.cs | 2 +-
src/log4net/Appender/MemoryAppender.cs | 16 +-
src/log4net/Appender/RemoteSyslogAppender.cs | 2 +-
src/log4net/Appender/RollingFileAppender.cs | 6 +-
src/log4net/Appender/TextWriterAppender.cs | 4 +-
src/log4net/Appender/UdpAppender.cs | 23 +-
src/log4net/Config/BasicConfigurator.cs | 2 +-
src/log4net/Config/PluginAttribute.cs | 2 +
src/log4net/Config/RepositoryAttribute.cs | 9 +-
.../Config/SecurityContextProviderAttribute.cs | 29 +-
src/log4net/Config/XmlConfigurator.cs | 8 +-
src/log4net/Config/XmlConfiguratorAttribute.cs | 6 +-
src/log4net/Core/DefaultRepositorySelector.cs | 12 +-
src/log4net/Core/ErrorCode.cs | 6 +-
src/log4net/Core/ExceptionEvaluator.cs | 27 +-
src/log4net/Core/FixFlags.cs | 2 +
src/log4net/Core/IErrorHandler.cs | 4 +-
src/log4net/Core/IRepositorySelector.cs | 31 +-
src/log4net/Core/Level.cs | 9 +-
src/log4net/Core/LevelCollection.cs | 120 ++++----
src/log4net/Core/LevelEvaluator.cs | 50 +--
src/log4net/Core/LevelMap.cs | 47 +--
src/log4net/Core/LocationInfo.cs | 14 +-
src/log4net/Core/LogException.cs | 19 +-
src/log4net/Core/LogImpl.cs | 340 +++++++++++----------
src/log4net/Core/LoggerManager.cs | 12 +-
src/log4net/Core/LoggerWrapperImpl.cs | 20 +-
src/log4net/Core/LoggingEvent.cs | 44 ++-
src/log4net/Core/SecurityContextProvider.cs | 2 +-
src/log4net/Core/TimeEvaluator.cs | 52 +---
src/log4net/Core/WrapperMap.cs | 16 +-
.../DateFormatter/AbsoluteTimeDateFormatter.cs | 6 +-
src/log4net/DateFormatter/DateTimeDateFormatter.cs | 2 +
src/log4net/DateFormatter/Iso8601DateFormatter.cs | 3 +-
src/log4net/DateFormatter/SimpleDateFormatter.cs | 32 +-
src/log4net/Filter/LevelMatchFilter.cs | 7 +-
src/log4net/Filter/LevelRangeFilter.cs | 36 +--
src/log4net/Filter/LoggerMatchFilter.cs | 32 +-
src/log4net/Filter/PropertyFilter.cs | 18 +-
src/log4net/Filter/StringMatchFilter.cs | 8 +-
src/log4net/ILog.cs | 217 ++++++-------
src/log4net/Layout/ExceptionLayout.cs | 19 +-
src/log4net/Layout/ILayout.cs | 2 +-
src/log4net/Layout/LayoutSkeleton.cs | 2 +-
src/log4net/Layout/Pattern/DatePatternConverter.cs | 2 +-
.../Layout/Pattern/NamedPatternConverter.cs | 1 +
.../Layout/Pattern/PatternLayoutConverter.cs | 2 +-
src/log4net/Layout/PatternLayout.cs | 14 +-
src/log4net/Layout/RawLayoutConverter.cs | 2 +-
src/log4net/Layout/RawPropertyLayout.cs | 7 +-
src/log4net/Layout/RawTimeStampLayout.cs | 9 +-
src/log4net/Layout/RawUtcTimeStampLayout.cs | 7 +-
src/log4net/Layout/SimpleLayout.cs | 15 +-
src/log4net/Layout/XmlLayout.cs | 4 +-
src/log4net/Layout/XmlLayoutBase.cs | 14 +-
src/log4net/Layout/XmlLayoutSchemaLog4j.cs | 17 +-
src/log4net/LogManager.cs | 166 +++-------
src/log4net/ObjectRenderer/DefaultRenderer.cs | 8 +-
src/log4net/ObjectRenderer/IObjectRenderer.cs | 2 +-
src/log4net/ObjectRenderer/RendererMap.cs | 26 +-
src/log4net/Plugin/PluginCollection.cs | 113 +++----
src/log4net/Plugin/PluginMap.cs | 47 +--
src/log4net/Repository/Hierarchy/Hierarchy.cs | 36 +--
.../Hierarchy/XmlHierarchyConfigurator.cs | 45 +--
src/log4net/Repository/ILoggerRepository.cs | 11 +-
src/log4net/Repository/LoggerRepositorySkeleton.cs | 17 +-
src/log4net/Util/AppenderAttachedImpl.cs | 11 +-
src/log4net/Util/ConverterInfo.cs | 4 +-
src/log4net/Util/CyclicBuffer.cs | 32 +-
src/log4net/Util/LevelMapping.cs | 4 +-
src/log4net/Util/LogicalThreadContextStack.cs | 25 +-
src/log4net/Util/NativeMethods.cs | 2 +-
src/log4net/Util/NullSecurityContext.cs | 2 +-
src/log4net/Util/OptionConverter.cs | 82 ++---
src/log4net/Util/PatternConverter.cs | 28 +-
src/log4net/Util/PatternString.cs | 19 +-
.../DatePatternConverter.cs | 2 +-
src/log4net/Util/ReadOnlyPropertiesDictionary.cs | 90 ++----
src/log4net/Util/SystemInfo.cs | 10 +-
src/log4net/Util/ThreadContextProperties.cs | 4 +-
src/log4net/Util/ThreadContextStack.cs | 10 +-
src/log4net/Util/Transform.cs | 7 +-
.../Util/TypeConverters/BooleanConverter.cs | 2 +-
.../ConversionNotSupportedException.cs | 31 +-
.../Util/TypeConverters/ConverterRegistry.cs | 4 +-
.../Util/TypeConverters/EncodingConverter.cs | 4 +-
.../Util/TypeConverters/IPAddressConverter.cs | 2 +-
.../Util/TypeConverters/PatternLayoutConverter.cs | 2 +-
.../Util/TypeConverters/PatternStringConverter.cs | 4 +-
src/log4net/Util/TypeConverters/TypeConverter.cs | 2 +-
.../Util/TypeConverters/TypeConverterAttribute.cs | 13 +-
src/log4net/Util/WindowsSecurityContext.cs | 29 +-
122 files changed, 1101 insertions(+), 1708 deletions(-)
diff --git a/src/log4net.Tests/Appender/AdoNet/Log4NetCommand.cs b/src/log4net.Tests/Appender/AdoNet/Log4NetCommand.cs
index b88277d3..161d4923 100644
--- a/src/log4net.Tests/Appender/AdoNet/Log4NetCommand.cs
+++ b/src/log4net.Tests/Appender/AdoNet/Log4NetCommand.cs
@@ -24,7 +24,7 @@ using System.Data;
namespace log4net.Tests.Appender.AdoNet;
-public class Log4NetCommand : IDbCommand
+internal sealed class Log4NetCommand : IDbCommand
{
public Log4NetCommand()
{
@@ -48,10 +48,7 @@ public class Log4NetCommand : IDbCommand
public int ExecuteNonQueryCount { get; private set; }
- public IDbDataParameter CreateParameter()
- {
- return new Log4NetParameter();
- }
+ public IDbDataParameter CreateParameter() => new Log4NetParameter();
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
public string? CommandText { get; set; }
@@ -68,25 +65,13 @@ public class Log4NetCommand : IDbCommand
public static Log4NetCommand? MostRecentInstance { get; private set; }
- public void Cancel()
- {
- throw new NotImplementedException();
- }
+ public void Cancel() => throw new NotImplementedException();
- public IDataReader ExecuteReader()
- {
- throw new NotImplementedException();
- }
+ public IDataReader ExecuteReader() => throw new NotImplementedException();
- public IDataReader ExecuteReader(CommandBehavior behavior)
- {
- throw new NotImplementedException();
- }
+ public IDataReader ExecuteReader(CommandBehavior behavior) => throw new NotImplementedException();
- public object ExecuteScalar()
- {
- throw new NotImplementedException();
- }
+ public object ExecuteScalar() => throw new NotImplementedException();
public IDbConnection? Connection
{
diff --git a/src/log4net.Tests/Appender/AdoNet/Log4NetConnection.cs b/src/log4net.Tests/Appender/AdoNet/Log4NetConnection.cs
index f31feeba..70485ea2 100644
--- a/src/log4net.Tests/Appender/AdoNet/Log4NetConnection.cs
+++ b/src/log4net.Tests/Appender/AdoNet/Log4NetConnection.cs
@@ -24,19 +24,13 @@ using System.Data;
namespace log4net.Tests.Appender.AdoNet;
-public class Log4NetConnection : IDbConnection
+internal sealed class Log4NetConnection : IDbConnection
{
private bool _open;
- public Log4NetConnection()
- {
- MostRecentInstance = this;
- }
+ public Log4NetConnection() => MostRecentInstance = this;
- public void Close()
- {
- _open = false;
- }
+ public void Close() => _open = false;
public ConnectionState State => _open ? ConnectionState.Open : ConnectionState.Closed;
@@ -44,39 +38,21 @@ public class Log4NetConnection : IDbConnection
public string? ConnectionString { get; set; }
#pragma warning restore CS8766
- public IDbTransaction BeginTransaction()
- {
- return new Log4NetTransaction();
- }
+ public IDbTransaction BeginTransaction() => new Log4NetTransaction();
- public IDbCommand CreateCommand()
- {
- return new Log4NetCommand();
- }
+ public IDbCommand CreateCommand() => new Log4NetCommand();
- public void Open()
- {
- _open = true;
- }
+ public void Open() => _open = true;
public static Log4NetConnection? MostRecentInstance { get; private set; }
- public IDbTransaction BeginTransaction(IsolationLevel il)
- {
- throw new NotImplementedException();
- }
+ public IDbTransaction BeginTransaction(IsolationLevel il) => throw new NotImplementedException();
- public void ChangeDatabase(string databaseName)
- {
- throw new NotImplementedException();
- }
+ public void ChangeDatabase(string databaseName) => throw new NotImplementedException();
public int ConnectionTimeout => throw new NotImplementedException();
public string Database => throw new NotImplementedException();
- public void Dispose()
- {
- throw new NotImplementedException();
- }
+ public void Dispose() => throw new NotImplementedException();
}
diff --git a/src/log4net.Tests/Appender/AdoNet/Log4NetParameterCollection.cs b/src/log4net.Tests/Appender/AdoNet/Log4NetParameterCollection.cs
index 65e72c98..3d5a660a 100644
--- a/src/log4net.Tests/Appender/AdoNet/Log4NetParameterCollection.cs
+++ b/src/log4net.Tests/Appender/AdoNet/Log4NetParameterCollection.cs
@@ -26,7 +26,7 @@ using System.Data;
namespace log4net.Tests.Appender.AdoNet;
-public class Log4NetParameterCollection : CollectionBase, IDataParameterCollection
+internal sealed class Log4NetParameterCollection : CollectionBase, IDataParameterCollection
{
private readonly Dictionary<string, int> _parameterNameToIndex = new(StringComparer.Ordinal);
@@ -55,13 +55,7 @@ public class Log4NetParameterCollection : CollectionBase, IDataParameterCollecti
set => InnerList[IndexOf(parameterName)] = value;
}
- public void RemoveAt(string parameterName)
- {
- throw new NotImplementedException();
- }
+ public void RemoveAt(string parameterName) => throw new NotImplementedException();
- public bool Contains(string parameterName)
- {
- throw new NotImplementedException();
- }
+ public bool Contains(string parameterName) => throw new NotImplementedException();
}
\ No newline at end of file
diff --git a/src/log4net.Tests/Appender/AdoNet/Log4NetTransaction.cs b/src/log4net.Tests/Appender/AdoNet/Log4NetTransaction.cs
index 3c92e5e9..27b3bb9c 100644
--- a/src/log4net.Tests/Appender/AdoNet/Log4NetTransaction.cs
+++ b/src/log4net.Tests/Appender/AdoNet/Log4NetTransaction.cs
@@ -24,7 +24,7 @@ using System.Data;
namespace log4net.Tests.Appender.AdoNet;
-public class Log4NetTransaction : IDbTransaction
+internal sealed class Log4NetTransaction : IDbTransaction
{
public void Commit()
{
@@ -40,8 +40,5 @@ public class Log4NetTransaction : IDbTransaction
public IsolationLevel IsolationLevel => throw new NotImplementedException();
- public void Dispose()
- {
- throw new NotImplementedException();
- }
+ public void Dispose() => throw new NotImplementedException();
}
diff --git a/src/log4net.Tests/Appender/CountingAppender.cs b/src/log4net.Tests/Appender/CountingAppender.cs
index 7a799ec3..e60e187c 100644
--- a/src/log4net.Tests/Appender/CountingAppender.cs
+++ b/src/log4net.Tests/Appender/CountingAppender.cs
@@ -44,17 +44,11 @@ public class CountingAppender : AppenderSkeleton
/// <summary>
/// Reset the counter to zero
/// </summary>
- public void ResetCounter()
- {
- Counter = 0;
- }
+ public void ResetCounter() => Counter = 0;
/// <summary>
/// Registers how many times the method has been called.
/// </summary>
- /// <param name="logEvent">The logging event.</param>
- protected override void Append(LoggingEvent logEvent)
- {
- Counter++;
- }
-}
+ /// <param name="loggingEvent">The logging event.</param>
+ protected override void Append(LoggingEvent loggingEvent) => Counter++;
+}
\ No newline at end of file
diff --git a/src/log4net.Tests/Appender/EventRaisingAppender.cs b/src/log4net.Tests/Appender/EventRaisingAppender.cs
index 21a8d28e..c9ac136e 100644
--- a/src/log4net.Tests/Appender/EventRaisingAppender.cs
+++ b/src/log4net.Tests/Appender/EventRaisingAppender.cs
@@ -27,20 +27,9 @@ namespace log4net.Tests.Appender;
/// <summary>
/// Provides data for the <see cref="EventRaisingAppender.LoggingEventAppended"/> event.
/// </summary>
-/// <seealso cref="System.EventArgs" />
-public class LoggingEventEventArgs : EventArgs
+public class LoggingEventEventArgs(LoggingEvent loggingEvent) : EventArgs
{
- public LoggingEvent LoggingEvent { get; private set; }
-
- public LoggingEventEventArgs(LoggingEvent loggingEvent)
- {
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
- LoggingEvent = loggingEvent;
- }
+ public LoggingEvent LoggingEvent { get; } = loggingEvent ?? throw new ArgumentNullException(nameof(loggingEvent));
}
/// <summary>
@@ -55,18 +44,13 @@ public class EventRaisingAppender : log4net.Appender.IAppender
public event EventHandler<LoggingEventEventArgs>? LoggingEventAppended;
protected void OnLoggingEventAppended(LoggingEventEventArgs e)
- {
- LoggingEventAppended?.Invoke(this, e);
- }
+ => LoggingEventAppended?.Invoke(this, e);
public void Close()
- {
- }
+ { }
public void DoAppend(LoggingEvent loggingEvent)
- {
- OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
- }
+ => OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
public string Name { get; set; } = string.Empty;
-}
+}
\ No newline at end of file
diff --git a/src/log4net.Tests/Context/LogicalThreadContextTest.cs b/src/log4net.Tests/Context/LogicalThreadContextTest.cs
index 118fa87b..35eddfaf 100644
--- a/src/log4net.Tests/Context/LogicalThreadContextTest.cs
+++ b/src/log4net.Tests/Context/LogicalThreadContextTest.cs
@@ -41,10 +41,7 @@ namespace log4net.Tests.Context;
public class LogicalThreadContextTest
{
[TearDown]
- public void TearDown()
- {
- Utils.RemovePropertyFromAllContexts();
- }
+ public void TearDown() => Utils.RemovePropertyFromAllContexts();
[Test]
public void TestLogicalThreadPropertiesPatternBasicGetSet()
@@ -100,7 +97,7 @@ public class LogicalThreadContextTest
Assert.That(stringAppender.GetString(), Is.EqualTo(testValueForCurrentContext), "Test logical thread properties value set");
stringAppender.Reset();
- var strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkProperties(x.ToString())));
+ string[] strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkProperties(x.ToString()))).ConfigureAwait(false);
// strings should be ["00AA0BB0", "01AA1BB1", "02AA2BB2", ...]
for (int i = 0; i < strings.Length; i++)
@@ -274,7 +271,7 @@ public class LogicalThreadContextTest
Assert.That(stringAppender.GetString(), Is.EqualTo(testValueForCurrentContext), "Test logical thread stack value set");
stringAppender.Reset();
- strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkStack(x.ToString())));
+ strings = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => SomeWorkStack(x.ToString()))).ConfigureAwait(false);
}
// strings should be ["Outer 0 AOuter 0 AOuter 0Outer 0 BOuter 0 B Outer 0", ...]
@@ -305,9 +302,9 @@ public class LogicalThreadContextTest
LogicalThreadContext.Properties[Utils.PropertyKey] = propertyName;
log.Info("TestMessage");
- await MoreWorkProperties(log, "A");
+ await MoreWorkProperties(log, "A").ConfigureAwait(false);
log.Info("TestMessage");
- await MoreWorkProperties(log, "B");
+ await MoreWorkProperties(log, "B").ConfigureAwait(false);
log.Info("TestMessage");
return stringAppender.GetString();
}
@@ -316,7 +313,7 @@ public class LogicalThreadContextTest
{
LogicalThreadContext.Properties[Utils.PropertyKey] = propertyName;
log.Info("TestMessage");
- await Task.Delay(1);
+ await Task.Delay(1).ConfigureAwait(false);
log.Info("TestMessage");
}
@@ -338,9 +335,9 @@ public class LogicalThreadContextTest
Assert.That(stringAppender.GetString(), Is.EqualTo(string.Format("Outer {0}", stackName)), "Test logical thread stack value set");
stringAppender.Reset();
- await MoreWorkStack(log, "A");
+ await MoreWorkStack(log, "A").ConfigureAwait(false);
log.Info("TestMessage");
- await MoreWorkStack(log, "B");
+ await MoreWorkStack(log, "B").ConfigureAwait(false);
log.Info("TestMessage");
}
@@ -352,7 +349,7 @@ public class LogicalThreadContextTest
using (LogicalThreadContext.Stacks[Utils.PropertyKey].Push(stackName))
{
log.Info("TestMessage");
- await Task.Delay(1);
+ await Task.Delay(1).ConfigureAwait(false);
log.Info("TestMessage");
}
}
diff --git a/src/log4net.Tests/Core/EvaluatorTest.cs b/src/log4net.Tests/Core/EvaluatorTest.cs
index 4640b9b6..544a9de3 100644
--- a/src/log4net.Tests/Core/EvaluatorTest.cs
+++ b/src/log4net.Tests/Core/EvaluatorTest.cs
@@ -30,6 +30,7 @@ using NUnit.Framework;
namespace log4net.Tests.Core;
[TestFixture]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")]
public class EvaluatorTest
{
private BufferingForwardingAppender _bufferingForwardingAppender = new();
diff --git a/src/log4net.Tests/Core/LoggingEventTest.cs b/src/log4net.Tests/Core/LoggingEventTest.cs
index 3ca7decc..29933285 100644
--- a/src/log4net.Tests/Core/LoggingEventTest.cs
+++ b/src/log4net.Tests/Core/LoggingEventTest.cs
@@ -38,6 +38,7 @@ public sealed class LoggingEventTest
[Test]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2300:Do not use insecure deserializer BinaryFormatter")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2301:Do not use insecure deserializer BinaryFormatter")]
public void SerializeDeserialize_BinaryFormatter()
{
Utils.InconclusiveOnMono();
@@ -88,6 +89,7 @@ public sealed class LoggingEventTest
/// </summary>
[Test]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2300:Do not use insecure deserializer BinaryFormatter")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2301:Do not use insecure deserializer BinaryFormatter")]
public void DeserializeV2()
{
Utils.InconclusiveOnMono();
diff --git a/src/log4net.Tests/Core/StringFormatTest.cs b/src/log4net.Tests/Core/StringFormatTest.cs
index 3036219c..b6879b7e 100644
--- a/src/log4net.Tests/Core/StringFormatTest.cs
+++ b/src/log4net.Tests/Core/StringFormatTest.cs
@@ -31,6 +31,7 @@ using NUnit.Framework;
namespace log4net.Tests.Core;
[TestFixture]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")]
public class StringFormatTest
{
private CultureInfo? _currentCulture;
diff --git a/src/log4net.Tests/DateFormatter/AbsoluteTimeDateFormatterTest.cs b/src/log4net.Tests/DateFormatter/AbsoluteTimeDateFormatterTest.cs
index 64250cd5..ddc774e1 100644
--- a/src/log4net.Tests/DateFormatter/AbsoluteTimeDateFormatterTest.cs
+++ b/src/log4net.Tests/DateFormatter/AbsoluteTimeDateFormatterTest.cs
@@ -30,15 +30,12 @@ namespace log4net.Tests.DateFormatter;
public class AbsoluteTimeDateFormatterTest
{
[TearDown]
- public void ResetCounts()
- {
- FormatterOne.Invocations = 0;
- }
+ public void ResetCounts() => FormatterOne.Invocations = 0;
[Test]
public void CacheWorksForSameTicks()
{
- StringWriter sw = new();
+ using StringWriter sw = new();
FormatterOne f1 = new();
FormatterOne f2 = new();
DateTime dt = DateTime.Now;
@@ -50,7 +47,7 @@ public class AbsoluteTimeDateFormatterTest
[Test]
public void CacheWorksForSameSecond()
{
- StringWriter sw = new();
+ using StringWriter sw = new();
FormatterOne f1 = new();
FormatterOne f2 = new();
DateTime dt1 = DateTime.Today;
@@ -63,7 +60,7 @@ public class AbsoluteTimeDateFormatterTest
[Test]
public void CacheExpiresWhenCrossingSecond()
{
- StringWriter sw = new();
+ using StringWriter sw = new();
FormatterOne f1 = new();
FormatterOne f2 = new();
DateTime dt1 = DateTime.Today.AddMinutes(1);
@@ -76,7 +73,7 @@ public class AbsoluteTimeDateFormatterTest
[Test]
public void CacheIsLocalToSubclass()
{
- StringWriter sw = new();
+ using StringWriter sw = new();
FormatterOne f1 = new();
FormatterTwo f2 = new();
DateTime dt1 = DateTime.Today.AddMinutes(10);
@@ -88,9 +85,9 @@ public class AbsoluteTimeDateFormatterTest
[Test]
public void TestFormattingResults()
{
- var formatter = new AbsoluteTimeDateFormatter();
- var sb = new StringBuilder();
- using var writer = new StringWriter(sb, CultureInfo.InvariantCulture);
+ AbsoluteTimeDateFormatter formatter = new();
+ StringBuilder sb = new();
+ using StringWriter writer = new(sb, CultureInfo.InvariantCulture);
// Tests for prepended 0 characters for 2-digit and 3-digit portions.
formatter.FormatDate(new DateTime(1970, 1, 1, 1, 1, 1).AddMilliseconds(1), writer);
@@ -108,12 +105,8 @@ internal class FormatterOne : AbsoluteTimeDateFormatter
{
internal static int Invocations;
- override protected void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
- {
- Invocations++;
- }
+ protected override void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer) => Invocations++;
}
internal sealed class FormatterTwo : FormatterOne
-{
-}
+{ }
diff --git a/src/log4net.Tests/Layout/PatternLayoutTest.cs b/src/log4net.Tests/Layout/PatternLayoutTest.cs
index b6522b75..5547c964 100644
--- a/src/log4net.Tests/Layout/PatternLayoutTest.cs
+++ b/src/log4net.Tests/Layout/PatternLayoutTest.cs
@@ -62,15 +62,9 @@ public class PatternLayoutTest
System.Threading.Thread.CurrentThread.CurrentUICulture = _currentUiCulture!;
}
- protected virtual PatternLayout NewPatternLayout()
- {
- return new PatternLayout();
- }
+ protected virtual PatternLayout NewPatternLayout() => new();
- protected virtual PatternLayout NewPatternLayout(string pattern)
- {
- return new PatternLayout(pattern);
- }
+ protected virtual PatternLayout NewPatternLayout(string pattern) => new(pattern);
[Test]
public void TestThreadPropertiesPattern()
@@ -324,10 +318,7 @@ public class PatternLayoutTest
/// <param name="writer"><see cref="TextWriter" /> that will receive the formatted result.</param>
/// <param name="loggingEvent">the event being logged</param>
/// <returns>the relevant location information</returns>
- protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
- {
- loggingEvent.WriteRenderedMessage(writer);
- }
+ protected override void Convert(TextWriter writer, LoggingEvent loggingEvent) => loggingEvent.WriteRenderedMessage(writer);
}
[Test]
@@ -342,7 +333,7 @@ public class PatternLayoutTest
ILog log1 = LogManager.GetLogger(rep.Name, "TestExceptionPattern");
- Exception exception = new("Oh no!");
+ InvalidOperationException exception = new("Oh no!");
log1.Info("TestMessage", exception);
Assert.That(stringAppender.GetString(), Is.EqualTo(SystemInfo.NullText));
@@ -352,9 +343,6 @@ public class PatternLayoutTest
private sealed class MessageAsNamePatternConverter : NamedPatternConverter
{
- protected override string GetFullyQualifiedName(LoggingEvent loggingEvent)
- {
- return loggingEvent.MessageObject?.ToString() ?? string.Empty;
- }
+ protected override string GetFullyQualifiedName(LoggingEvent loggingEvent) => loggingEvent.MessageObject?.ToString() ?? string.Empty;
}
}
\ No newline at end of file
diff --git a/src/log4net.Tests/Layout/XmlLayoutTest.cs b/src/log4net.Tests/Layout/XmlLayoutTest.cs
index 2bebff11..2f323a3b 100644
--- a/src/log4net.Tests/Layout/XmlLayoutTest.cs
+++ b/src/log4net.Tests/Layout/XmlLayoutTest.cs
@@ -106,7 +106,7 @@ public sealed class XmlLayoutTest
public void TestBasicEventLogging()
{
using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
layout.Format(writer, new LoggingEvent(evt));
@@ -119,8 +119,8 @@ public sealed class XmlLayoutTest
[Test]
public void TestIllegalCharacterMasking()
{
- using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ using StringWriter writer = new();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
evt.Message = "This is a masked char->\uFFFF";
@@ -135,8 +135,8 @@ public sealed class XmlLayoutTest
[Test]
public void TestCdataEscaping1()
{
- using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ using StringWriter writer = new();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
//The &'s trigger the use of a cdata block
@@ -152,8 +152,8 @@ public sealed class XmlLayoutTest
[Test]
public void TestCdataEscaping2()
{
- using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ using StringWriter writer = new();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
//The &'s trigger the use of a cdata block
@@ -169,8 +169,8 @@ public sealed class XmlLayoutTest
[Test]
public void TestCdataEscaping3()
{
- using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ using StringWriter writer = new();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
//The &'s trigger the use of a cdata block
@@ -186,8 +186,8 @@ public sealed class XmlLayoutTest
[Test]
public void TestBase64EventLogging()
{
- using TextWriter writer = new StringWriter();
- var layout = new XmlLayout();
+ using StringWriter writer = new();
+ XmlLayout layout = new();
LoggingEventData evt = CreateBaseEvent();
layout.Base64EncodeMessage = true;
@@ -204,8 +204,8 @@ public sealed class XmlLayoutTest
LoggingEventData evt = CreateBaseEvent();
evt.Properties!["Property1"] = "prop1";
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -224,8 +224,8 @@ public sealed class XmlLayoutTest
LoggingEventData evt = CreateBaseEvent();
evt.Properties!["Property1"] = "prop1";
- var layout = new XmlLayout { Base64EncodeProperties = true };
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new() { Base64EncodeProperties = true };
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -244,8 +244,8 @@ public sealed class XmlLayoutTest
LoggingEventData evt = CreateBaseEvent();
evt.Properties!["Property1"] = "prop1 \"quoted\"";
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -264,8 +264,8 @@ public sealed class XmlLayoutTest
LoggingEventData evt = CreateBaseEvent();
evt.Properties!["Property1"] = "mask this ->\uFFFF";
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -284,8 +284,8 @@ public sealed class XmlLayoutTest
LoggingEventData evt = CreateBaseEvent();
evt.Properties!["Property\uFFFF"] = "mask this ->\uFFFF";
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -301,8 +301,8 @@ public sealed class XmlLayoutTest
[Test]
public void BracketsInStackTracesKeepLogWellFormed()
{
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -314,7 +314,7 @@ public sealed class XmlLayoutTest
{
throw null!;
}
- catch (Exception ex)
+ catch (Exception ex) when (ex is not null)
{
log1.Error($"Error {foo}", ex);
}
@@ -323,15 +323,15 @@ public sealed class XmlLayoutTest
Bar(42);
// really only asserts there is no exception
- var loggedDoc = new XmlDocument();
+ XmlDocument loggedDoc = new();
loggedDoc.LoadXml(stringAppender.GetString());
}
[Test]
public void BracketsInStackTracesAreEscapedProperly()
{
- var layout = new XmlLayout();
- var stringAppender = new StringAppender { Layout = layout };
+ XmlLayout layout = new();
+ StringAppender stringAppender = new() { Layout = layout };
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
@@ -343,7 +343,7 @@ public sealed class XmlLayoutTest
{
throw null!;
}
- catch (Exception ex)
+ catch (Exception ex) when (ex is not null)
{
log1.Error($"Error {foo}", ex);
}
@@ -357,10 +357,10 @@ public sealed class XmlLayoutTest
const string nodeName = "exception";
#endif
- var log = stringAppender.GetString();
- var startOfExceptionText = log.IndexOf("<" + nodeName + ">", StringComparison.InvariantCulture) + nodeName.Length + 2;
- var endOfExceptionText = log.IndexOf("</" + nodeName + ">", StringComparison.InvariantCulture);
- var sub = log.Substring(startOfExceptionText, endOfExceptionText - startOfExceptionText);
+ string log = stringAppender.GetString();
+ int startOfExceptionText = log.IndexOf("<" + nodeName + ">", StringComparison.InvariantCulture) + nodeName.Length + 2;
+ int endOfExceptionText = log.IndexOf("</" + nodeName + ">", StringComparison.InvariantCulture);
+ string sub = log.Substring(startOfExceptionText, endOfExceptionText - startOfExceptionText);
if (sub.StartsWith("<![CDATA["))
{
Assert.That(sub, Does.EndWith("]]>"));
diff --git a/src/log4net.Tests/Util/EnvironmentPatternConverterTest.cs b/src/log4net.Tests/Util/EnvironmentPatternConverterTest.cs
index ff41af19..f8008118 100644
--- a/src/log4net.Tests/Util/EnvironmentPatternConverterTest.cs
+++ b/src/log4net.Tests/Util/EnvironmentPatternConverterTest.cs
@@ -41,7 +41,7 @@ public sealed class EnvironmentPatternConverterTest
[Platform(Include = "Win", Reason = @"https://learn.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable")]
public void SystemLevelEnvironmentVariable()
{
- var converter = new EnvironmentPatternConverter();
+ EnvironmentPatternConverter converter = new();
try
{
Environment.SetEnvironmentVariable(EnvironmentVariableName, SystemLevelValue, EnvironmentVariableTarget.Machine);
@@ -53,7 +53,7 @@ public sealed class EnvironmentPatternConverterTest
converter.Option = EnvironmentVariableName;
- var sw = new StringWriter();
+ using StringWriter sw = new();
converter.Convert(sw, null);
Assert.That(sw.ToString(), Is.EqualTo(SystemLevelValue), "System level environment variable not expended correctly.");
@@ -68,12 +68,12 @@ public sealed class EnvironmentPatternConverterTest
[Platform(Include = "Win", Reason = @"https://learn.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable")]
public void UserLevelEnvironmentVariable()
{
- var converter = new EnvironmentPatternConverter();
+ EnvironmentPatternConverter converter = new();
Environment.SetEnvironmentVariable(EnvironmentVariableName, UserLevelValue, EnvironmentVariableTarget.User);
converter.Option = EnvironmentVariableName;
- var sw = new StringWriter();
+ using StringWriter sw = new();
converter.Convert(sw, null);
Assert.That(sw.ToString(), Is.EqualTo(UserLevelValue), "User level environment variable not expended correctly.");
@@ -84,12 +84,12 @@ public sealed class EnvironmentPatternConverterTest
[Test]
public void ProcessLevelEnvironmentVariable()
{
- var converter = new EnvironmentPatternConverter();
+ EnvironmentPatternConverter converter = new();
Environment.SetEnvironmentVariable(EnvironmentVariableName, ProcessLevelValue);
converter.Option = EnvironmentVariableName;
- var sw = new StringWriter();
+ using StringWriter sw = new();
converter.Convert(sw, null);
Assert.That(sw.ToString(), Is.EqualTo(ProcessLevelValue), "Process level environment variable not expended correctly.");
diff --git a/src/log4net.Tests/Util/LogLogTest.cs b/src/log4net.Tests/Util/LogLogTest.cs
index 000b2890..e72c1020 100644
--- a/src/log4net.Tests/Util/LogLogTest.cs
+++ b/src/log4net.Tests/Util/LogLogTest.cs
@@ -74,9 +74,9 @@ public class LogLogTest
[Test]
public void LogReceivedAdapter()
{
- var messages = new List<LogLog>();
+ List<LogLog> messages = new();
- using var _ = new LogLog.LogReceivedAdapter(messages);
+ using LogLog.LogReceivedAdapter _ = new(messages);
LogLog.Debug(GetType(), "Won't be recorded");
LogLog.Error(GetType(), "This will be recorded.");
LogLog.Error(GetType(), "This will be recorded.");
@@ -96,12 +96,14 @@ public class LogLogTest
}
}
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5394:Do not use insecure randomness",
+ Justification = "no cryptography")]
private void LogReceivedAdapterThreadingCore(int seed)
{
- var messages = new List<LogLog>(1);
- var syncRoot = ((ICollection)messages).SyncRoot;
- var random = new Random(seed);
- using var _ = new LogLog.LogReceivedAdapter(messages);
+ List<LogLog> messages = new(1);
+ object syncRoot = ((ICollection)messages).SyncRoot;
+ Random random = new(seed);
+ using LogLog.LogReceivedAdapter _ = new(messages);
Parallel.For(0, 10, i =>
{
if (random.Next(10) > 8)
diff --git a/src/log4net.Tests/Util/PropertiesDictionaryTest.cs b/src/log4net.Tests/Util/PropertiesDictionaryTest.cs
index d0f65558..3817e177 100644
--- a/src/log4net.Tests/Util/PropertiesDictionaryTest.cs
+++ b/src/log4net.Tests/Util/PropertiesDictionaryTest.cs
@@ -19,7 +19,6 @@
#if NET462_OR_GREATER
-using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
@@ -39,6 +38,8 @@ namespace log4net.Tests.Util;
public class PropertiesDictionaryTest
{
[Test]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2300:Do not use insecure deserializer BinaryFormatter")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2301:Do not use insecure deserializer BinaryFormatter")]
public void TestSerialization()
{
PropertiesDictionary pd = new();
diff --git a/src/log4net.Tests/Util/RandomStringPatternConverterTest.cs b/src/log4net.Tests/Util/RandomStringPatternConverterTest.cs
index 4fdec131..48945002 100644
--- a/src/log4net.Tests/Util/RandomStringPatternConverterTest.cs
+++ b/src/log4net.Tests/Util/RandomStringPatternConverterTest.cs
@@ -26,9 +26,6 @@ namespace log4net.Tests.Util;
/// <summary>
/// Used for internal unit testing the <see cref="RandomStringPatternConverter"/> class.
/// </summary>
-/// <remarks>
-/// Used for internal unit testing the <see cref="RandomStringPatternConverter"/> class.
-/// </remarks>
[TestFixture]
public class RandomStringPatternConverterTest
{
@@ -38,7 +35,7 @@ public class RandomStringPatternConverterTest
RandomStringPatternConverter converter = new();
// Check default string length
- StringWriter sw = new();
+ using StringWriter sw = new();
converter.Convert(sw, null);
Assert.That(sw.ToString(), Has.Length.EqualTo(4), "Default string length should be 4");
@@ -47,17 +44,17 @@ public class RandomStringPatternConverterTest
converter.Option = "7";
converter.ActivateOptions();
- sw = new StringWriter();
- converter.Convert(sw, null);
+ using StringWriter sw2 = new();
+ converter.Convert(sw2, null);
- string string1 = sw.ToString();
+ string string1 = sw2.ToString();
Assert.That(string1, Has.Length.EqualTo(7), "string length should be 7");
// Check for duplicate result
- sw = new StringWriter();
- converter.Convert(sw, null);
+ using StringWriter sw3 = new();
+ converter.Convert(sw3, null);
- string string2 = sw.ToString();
- Assert.That(string1 != string2, "strings should be different");
+ string string2 = sw3.ToString();
+ Assert.That(string1, Is.Not.EqualTo(string2), "strings should be different");
}
}
\ No newline at end of file
diff --git a/src/log4net/Appender/AnsiColorTerminalAppender.cs b/src/log4net/Appender/AnsiColorTerminalAppender.cs
index 575a7c94..b685c456 100644
--- a/src/log4net/Appender/AnsiColorTerminalAppender.cs
+++ b/src/log4net/Appender/AnsiColorTerminalAppender.cs
@@ -234,7 +234,7 @@ public class AnsiColorTerminalAppender : AppenderSkeleton
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
/// <para>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </para>
/// <para>
/// The format of the output will depend on the appender layout.
diff --git a/src/log4net/Appender/AppenderSkeleton.cs b/src/log4net/Appender/AppenderSkeleton.cs
index 2f6290e5..216e4ec0 100644
--- a/src/log4net/Appender/AppenderSkeleton.cs
+++ b/src/log4net/Appender/AppenderSkeleton.cs
@@ -37,7 +37,7 @@ namespace log4net.Appender;
/// </para>
/// <para>
/// Appenders can also implement the <see cref="IOptionHandler"/> interface. Therefore
-/// they would require that the <see cref="M:IOptionHandler.ActivateOptions()"/> method
+/// they would require that the <see cref="IOptionHandler.ActivateOptions()"/> method
/// be called after the appenders properties have been configured.
/// </para>
/// </remarks>
@@ -45,11 +45,6 @@ namespace log4net.Appender;
/// <author>Gert Driesen</author>
public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandler, IFlushable
{
- /// <summary>
- /// SyncRoot
- /// </summary>
- private protected object SyncRoot { get; } = new();
-
/// <summary>
/// Default constructor
/// </summary>
@@ -212,13 +207,13 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// <summary>
/// Performs threshold checks and invokes filters before
/// delegating actual logging to the subclasses specific
- /// <see cref="M:Append(LoggingEvent)"/> method.
+ /// <see cref="Append(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
/// <para>
/// This method cannot be overridden by derived classes. A
- /// derived class should override the <see cref="M:Append(LoggingEvent)"/> method
+ /// derived class should override the <see cref="Append(LoggingEvent)"/> method
/// which is called by this method.
/// </para>
/// <para>
@@ -240,14 +235,14 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// </item>
/// <item>
/// <description>
- /// Calls <see cref="M:PreAppendCheck()"/> and checks that
+ /// Calls <see cref="PreAppendCheck()"/> and checks that
/// it returns <c>true</c>.</description>
/// </item>
/// </list>
/// </para>
/// <para>
/// If all of the above steps succeed then the <paramref name="loggingEvent"/>
- /// will be passed to the abstract <see cref="M:Append(LoggingEvent)"/> method.
+ /// will be passed to the abstract <see cref="Append(LoggingEvent)"/> method.
/// </para>
/// </remarks>
public void DoAppend(LoggingEvent loggingEvent)
@@ -294,13 +289,13 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// <summary>
/// Performs threshold checks and invokes filters before
/// delegating actual logging to the subclasses specific
- /// <see cref="M:Append(LoggingEvent[])"/> method.
+ /// <see cref="Append(LoggingEvent[])"/> method.
/// </summary>
/// <param name="loggingEvents">The array of events to log.</param>
/// <remarks>
/// <para>
/// This method cannot be overridden by derived classes. A
- /// derived class should override the <see cref="M:Append(LoggingEvent[])"/> method
+ /// derived class should override the <see cref="Append(LoggingEvent[])"/> method
/// which is called by this method.
/// </para>
/// <para>
@@ -322,14 +317,14 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// </item>
/// <item>
/// <description>
- /// Calls <see cref="M:PreAppendCheck()"/> and checks that
+ /// Calls <see cref="PreAppendCheck()"/> and checks that
/// it returns <c>true</c>.</description>
/// </item>
/// </list>
/// </para>
/// <para>
/// If all of the above steps succeed then the <paramref name="loggingEvents"/>
- /// will be passed to the <see cref="M:Append(LoggingEvent[])"/> method.
+ /// will be passed to the <see cref="Append(LoggingEvent[])"/> method.
/// </para>
/// </remarks>
public void DoAppend(LoggingEvent[] loggingEvents)
@@ -417,7 +412,8 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// </remarks>
protected virtual bool FilterEvent(LoggingEvent loggingEvent)
{
- if (!IsAsSevereAsThreshold(loggingEvent.EnsureNotNull().Level))
+ loggingEvent.EnsureNotNull();
+ if (!IsAsSevereAsThreshold(loggingEvent.Level))
{
return false;
}
@@ -459,11 +455,7 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// </remarks>
public virtual void AddFilter(IFilter filter)
{
- if (filter is null)
- {
- throw new ArgumentNullException(nameof(filter));
- }
-
+ filter.EnsureNotNull();
if (FilterHead is null)
{
FilterHead = _tailFilter = filter;
@@ -483,10 +475,7 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// Clears the filter list for this appender.
/// </para>
/// </remarks>
- public virtual void ClearFilters()
- {
- FilterHead = _tailFilter = null;
- }
+ public virtual void ClearFilters() => FilterHead = _tailFilter = null;
/// <summary>
/// Checks if the message level is below this appender's threshold.
@@ -497,10 +486,7 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// requirements of this appender. A null level always maps to <c>true</c>,
/// the equivalent of <see cref="Level.All"/>.
/// </returns>
- protected virtual bool IsAsSevereAsThreshold(Level? level)
- {
- return level is null || level >= Threshold;
- }
+ protected virtual bool IsAsSevereAsThreshold(Level? level) => level is null || level >= Threshold;
/// <summary>
/// Is called when the appender is closed. Derived classes should override
@@ -530,12 +516,12 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// A subclass must implement this method to perform
/// logging of the <paramref name="loggingEvent"/>.
/// </para>
- /// <para>This method will be called by <see cref="M:DoAppend(LoggingEvent)"/>
+ /// <para>This method will be called by <see cref="DoAppend(LoggingEvent)"/>
/// if all the conditions listed for that method are met.
/// </para>
/// <para>
/// To restrict the logging of events in the appender
- /// override the <see cref="M:PreAppendCheck()"/> method.
+ /// override the <see cref="PreAppendCheck()"/> method.
/// </para>
/// </remarks>
protected abstract void Append(LoggingEvent loggingEvent);
@@ -546,12 +532,12 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// <param name="loggingEvents">the array of logging events</param>
/// <remarks>
/// <para>
- /// This base class implementation calls the <see cref="M:Append(LoggingEvent)"/>
+ /// This base class implementation calls the <see cref="Append(LoggingEvent)"/>
/// method for each element in the bulk array.
/// </para>
/// <para>
/// A subclass that can better process a bulk array of events should
- /// override this method in addition to <see cref="M:Append(LoggingEvent)"/>.
+ /// override this method in addition to <see cref="Append(LoggingEvent)"/>.
/// </para>
/// </remarks>
protected virtual void Append(LoggingEvent[] loggingEvents)
@@ -568,12 +554,12 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// <param name="loggingEvents">The logging events</param>
/// <remarks>
/// <para>
- /// This base class implementation calls the <see cref="M:Append(LoggingEvent)"/>
+ /// This base class implementation calls the <see cref="Append(LoggingEvent)"/>
/// method for each element in the bulk array.
/// </para>
/// <para>
/// A subclass that can better process a bulk array of events should
- /// override this method in addition to <see cref="M:Append(LoggingEvent)"/>.
+ /// override this method in addition to <see cref="Append(LoggingEvent)"/>.
/// </para>
/// </remarks>
protected virtual void Append(IEnumerable<LoggingEvent> loggingEvents)
@@ -585,23 +571,23 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
}
/// <summary>
- /// Called before <see cref="M:Append(LoggingEvent)"/> as a precondition.
+ /// Called before <see cref="Append(LoggingEvent)"/> as a precondition.
/// </summary>
/// <remarks>
/// <para>
- /// This method is called by <see cref="M:DoAppend(LoggingEvent)"/>
- /// before the call to the abstract <see cref="M:Append(LoggingEvent)"/> method.
+ /// This method is called by <see cref="DoAppend(LoggingEvent)"/>
+ /// before the call to the abstract <see cref="Append(LoggingEvent)"/> method.
/// </para>
/// <para>
/// This method can be overridden in a subclass to extend the checks
- /// made before the event is passed to the <see cref="M:Append(LoggingEvent)"/> method.
+ /// made before the event is passed to the <see cref="Append(LoggingEvent)"/> method.
/// </para>
/// <para>
/// A subclass should ensure that they delegate this call to
/// this base class if it is overridden.
/// </para>
/// </remarks>
- /// <returns><c>true</c> if the call to <see cref="M:Append(LoggingEvent)"/> should proceed.</returns>
+ /// <returns><c>true</c> if the call to <see cref="Append(LoggingEvent)"/> should proceed.</returns>
protected virtual bool PreAppendCheck()
{
if ((Layout is null) && RequiresLayout)
@@ -631,7 +617,7 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// </para>
/// <para>
/// Where possible use the alternative version of this method
- /// <see cref="M:RenderLoggingEvent(TextWriter,LoggingEvent)"/>.
+ /// <see cref="RenderLoggingEvent(TextWriter,LoggingEvent)"/>.
/// That method streams the rendering onto an existing Writer
/// which can give better performance if the caller already has
/// a <see cref="TextWriter"/> open and ready for writing.
@@ -669,9 +655,9 @@ public abstract class AppenderSkeleton : IAppender, IBulkAppender, IOptionHandle
/// will append the exception text to the rendered string.
/// </para>
/// <para>
- /// Use this method in preference to <see cref="M:RenderLoggingEvent(LoggingEvent)"/>
+ /// Use this method in preference to <see cref="RenderLoggingEvent(LoggingEvent)"/>
/// where possible. If, however, the caller needs to render the event
- /// to a string then <see cref="M:RenderLoggingEvent(LoggingEvent)"/> does
+ /// to a string then <see cref="RenderLoggingEvent(LoggingEvent)"/> does
/// provide an efficient mechanism for doing so.
/// </para>
/// </remarks>
diff --git a/src/log4net/Appender/AspNetTraceAppender.cs b/src/log4net/Appender/AspNetTraceAppender.cs
index 1a35230d..536001e2 100644
--- a/src/log4net/Appender/AspNetTraceAppender.cs
+++ b/src/log4net/Appender/AspNetTraceAppender.cs
@@ -43,8 +43,8 @@ namespace log4net.Appender;
/// whether tracing is displayed to a page, to the trace viewer, or both.
/// </para>
/// <para>
-/// The logging event is passed to the <see cref="M:TraceContext.Write(string)"/> or
-/// <see cref="M:TraceContext.Warn(string)"/> method depending on the level of the logging event.
+/// The logging event is passed to the <see cref="TraceContext.Write(string)"/> or
+/// <see cref="TraceContext.Warn(string)"/> method depending on the level of the logging event.
/// The event's logger name is the default value for the category parameter of the Write/Warn method.
/// </para>
/// </remarks>
diff --git a/src/log4net/Appender/BufferingAppenderSkeleton.cs b/src/log4net/Appender/BufferingAppenderSkeleton.cs
index 5b8d8680..f98efbc2 100644
--- a/src/log4net/Appender/BufferingAppenderSkeleton.cs
+++ b/src/log4net/Appender/BufferingAppenderSkeleton.cs
@@ -22,7 +22,6 @@ using System;
using log4net.Util;
using log4net.Core;
using System.Collections.Generic;
-using System.Linq;
namespace log4net.Appender;
@@ -39,7 +38,7 @@ namespace log4net.Appender;
/// the underlying database in one go.
/// </para>
/// <para>
-/// Subclasses should override the <see cref="M:SendBuffer(LoggingEvent[])"/>
+/// Subclasses should override the <see cref="SendBuffer(LoggingEvent[])"/>
/// method to deliver the buffered events.
/// </para>
/// <para>The BufferingAppenderSkeleton maintains a fixed size cyclic
@@ -49,14 +48,14 @@ namespace log4net.Appender;
/// <para>A <see cref="ITriggeringEventEvaluator"/> is used to inspect
/// each event as it arrives in the appender. If the <see cref="Evaluator"/>
/// triggers, then the current buffer is sent immediately
-/// (see <see cref="M:SendBuffer(LoggingEvent[])"/>). Otherwise the event
+/// (see <see cref="SendBuffer(LoggingEvent[])"/>). Otherwise the event
/// is stored in the buffer. For example, an evaluator can be used to
/// deliver the events immediately when an ERROR event arrives.
/// </para>
/// <para>
/// The buffering appender can be configured in a <see cref="Lossy"/> mode.
/// By default the appender is NOT lossy. When the buffer is full all
-/// the buffered events are sent with <see cref="M:SendBuffer(LoggingEvent[])"/>.
+/// the buffered events are sent with <see cref="SendBuffer(LoggingEvent[])"/>.
/// If the <see cref="Lossy"/> property is set to <c>true</c> then the
/// buffer will not be sent when it is full, and new events arriving
/// in the appender will overwrite the oldest event in the buffer.
@@ -161,7 +160,7 @@ public abstract class BufferingAppenderSkeleton : AppenderSkeleton
/// <para>
/// The evaluator will be called for each event that is appended to this
/// appender. If the evaluator triggers then the current buffer will
- /// immediately be sent (see <see cref="M:SendBuffer(LoggingEvent[])"/>).
+ /// immediately be sent (see <see cref="SendBuffer(LoggingEvent[])"/>).
/// </para>
/// <para>If <see cref="Lossy"/> is set to <c>true</c> then an
/// <see cref="Evaluator"/> must be specified.</para>
@@ -178,7 +177,7 @@ public abstract class BufferingAppenderSkeleton : AppenderSkeleton
/// <para>
/// The evaluator will be called for each event that is discarded from this
/// appender. If the evaluator triggers then the current buffer will immediately
- /// be sent (see <see cref="M:SendBuffer(LoggingEvent[])"/>).
+ /// be sent (see <see cref="SendBuffer(LoggingEvent[])"/>).
/// </para>
/// </remarks>
public ITriggeringEventEvaluator? LossyEvaluator { get; set; }
@@ -353,7 +352,7 @@ public abstract class BufferingAppenderSkeleton : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">the event to log</param>
/// <remarks>
@@ -377,7 +376,7 @@ public abstract class BufferingAppenderSkeleton : AppenderSkeleton
/// </list>
/// <para>
/// Before the event is stored in the buffer it is fixed
- /// (see <see cref="M:LoggingEvent.FixVolatileData(FixFlags)"/>) to ensure that
+ /// (see <see cref="LoggingEvent.FixVolatileData(FixFlags)"/>) to ensure that
/// any data referenced by the event will be valid when the buffer
/// is processed.
/// </para>
@@ -464,7 +463,7 @@ public abstract class BufferingAppenderSkeleton : AppenderSkeleton
/// <param name="buffer">The buffer containing the events that need to be sent.</param>
/// <remarks>
/// <para>
- /// The subclass must override <see cref="M:SendBuffer(LoggingEvent[])"/>.
+ /// The subclass must override <see cref="SendBuffer(LoggingEvent[])"/>.
/// </para>
/// </remarks>
protected virtual void SendFromBuffer(LoggingEvent? firstLoggingEvent, CyclicBuffer buffer)
diff --git a/src/log4net/Appender/BufferingForwardingAppender.cs b/src/log4net/Appender/BufferingForwardingAppender.cs
index fcc69ff8..324f4e9a 100644
--- a/src/log4net/Appender/BufferingForwardingAppender.cs
+++ b/src/log4net/Appender/BufferingForwardingAppender.cs
@@ -17,8 +17,6 @@
//
#endregion
-using System;
-
using log4net.Util;
using log4net.Core;
@@ -98,13 +96,10 @@ public class BufferingForwardingAppender : BufferingAppenderSkeleton, IAppenderA
/// </remarks>
public virtual void AddAppender(IAppender appender)
{
- if (appender is null)
- {
- throw new ArgumentNullException(nameof(appender));
- }
+ appender.EnsureNotNull();
lock (LockObj)
{
- _appenderAttachedImpl ??= new AppenderAttachedImpl();
+ _appenderAttachedImpl ??= new();
_appenderAttachedImpl.AddAppender(appender);
}
}
diff --git a/src/log4net/Appender/ColoredConsoleAppender.cs b/src/log4net/Appender/ColoredConsoleAppender.cs
index 6474116c..65fbd484 100644
--- a/src/log4net/Appender/ColoredConsoleAppender.cs
+++ b/src/log4net/Appender/ColoredConsoleAppender.cs
@@ -19,7 +19,6 @@
using System;
using System.IO;
-using System.Runtime.InteropServices;
using System.Text;
using log4net.Core;
using log4net.Util;
@@ -182,7 +181,7 @@ public class ColoredConsoleAppender : AppenderSkeleton
public void AddMapping(LevelColors mapping) => _levelMapping.Add(mapping);
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
diff --git a/src/log4net/Appender/ConsoleAppender.cs b/src/log4net/Appender/ConsoleAppender.cs
index 60cf8f44..62233abc 100644
--- a/src/log4net/Appender/ConsoleAppender.cs
+++ b/src/log4net/Appender/ConsoleAppender.cs
@@ -81,7 +81,7 @@ public class ConsoleAppender : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
diff --git a/src/log4net/Appender/DebugAppender.cs b/src/log4net/Appender/DebugAppender.cs
index a321c529..caf45348 100644
--- a/src/log4net/Appender/DebugAppender.cs
+++ b/src/log4net/Appender/DebugAppender.cs
@@ -35,7 +35,7 @@ namespace log4net.Appender;
/// debug system.
/// </para>
/// <para>
-/// Events are written using the <see cref="M:System.Diagnostics.Debug.Write(string,string)"/>
+/// Events are written using the <see cref="System.Diagnostics.Debug.Write(string,string)"/>
/// method. The event's logger name is passed as the value for the category name to the Write method.
/// </para>
/// </remarks>
diff --git a/src/log4net/Appender/EventLogAppender.cs b/src/log4net/Appender/EventLogAppender.cs
index 177fff60..8b96c3f5 100644
--- a/src/log4net/Appender/EventLogAppender.cs
+++ b/src/log4net/Appender/EventLogAppender.cs
@@ -298,7 +298,7 @@ public class EventLogAppender : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/>
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/>
/// method.
/// </summary>
/// <param name="loggingEvent">the event to log</param>
diff --git a/src/log4net/Appender/FileAppender.cs b/src/log4net/Appender/FileAppender.cs
index 7bf00a07..be8a9b6c 100644
--- a/src/log4net/Appender/FileAppender.cs
+++ b/src/log4net/Appender/FileAppender.cs
@@ -104,7 +104,7 @@ public class FileAppender : TextWriterAppender
{ }
}
- private readonly object syncRoot = new();
+ private readonly object _syncRoot = new();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "todo")]
private Stream? _realStream;
private int _lockLevel;
@@ -171,7 +171,7 @@ public class FileAppender : TextWriterAppender
public bool AcquireLock()
{
bool ret = false;
- lock (syncRoot)
+ lock (_syncRoot)
{
if (_lockLevel == 0)
{
@@ -191,7 +191,7 @@ public class FileAppender : TextWriterAppender
public void ReleaseLock()
{
- lock (syncRoot)
+ lock (_syncRoot)
{
_lockLevel--;
if (_lockLevel == 0)
@@ -477,8 +477,8 @@ public class FileAppender : TextWriterAppender
/// </remarks>
public override void OpenFile(string filename, bool append, Encoding encoding)
{
- this._filename = filename;
- this._append = append;
+ _filename = filename;
+ _append = append;
}
/// <summary>
@@ -1017,7 +1017,7 @@ public class FileAppender : TextWriterAppender
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/>
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/>
/// method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
@@ -1046,7 +1046,7 @@ public class FileAppender : TextWriterAppender
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent[])"/>
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent[])"/>
/// method.
/// </summary>
/// <param name="loggingEvents">The array of events to log.</param>
@@ -1213,14 +1213,14 @@ public class FileAppender : TextWriterAppender
}
}
- lock (SyncRoot)
+ lock (LockObj)
{
Reset();
LogLog.Debug(_declaringType, "Opening file for writing [" + fileName + "] append [" + append + "]");
// Save these for later, allowing retries if file open fails
- this._fileName = fileName;
+ _fileName = fileName;
AppendToFile = append;
LockingModel.CurrentAppender = this;
@@ -1250,9 +1250,9 @@ public class FileAppender : TextWriterAppender
/// <param name="fileStream">the file stream that has been opened for writing</param>
/// <remarks>
/// <para>
- /// This implementation of <see cref="M:SetQWForFiles(Stream)"/> creates a <see cref="StreamWriter"/>
+ /// This implementation of <see cref="SetQwForFiles(Stream)"/> creates a <see cref="StreamWriter"/>
/// over the <paramref name="fileStream"/> and passes it to the
- /// <see cref="M:SetQWForFiles(TextWriter)"/> method.
+ /// <see cref="SetQwForFiles(TextWriter)"/> method.
/// </para>
/// <para>
/// This method can be overridden by subclasses that want to wrap the
@@ -1278,7 +1278,8 @@ public class FileAppender : TextWriterAppender
/// wrap the <see cref="TextWriter"/> in some way.
/// </para>
/// </remarks>
- protected virtual void SetQwForFiles(TextWriter writer) => QuietWriter = new QuietTextWriter(writer, ErrorHandler);
+ protected virtual void SetQwForFiles(TextWriter writer)
+ => QuietWriter = new(writer, ErrorHandler);
/// <summary>
/// Convert a path into a fully qualified path.
diff --git a/src/log4net/Appender/ForwardingAppender.cs b/src/log4net/Appender/ForwardingAppender.cs
index 28095ed4..609a65d9 100644
--- a/src/log4net/Appender/ForwardingAppender.cs
+++ b/src/log4net/Appender/ForwardingAppender.cs
@@ -17,8 +17,6 @@
//
#endregion
-using System;
-
using log4net.Util;
using log4net.Core;
@@ -52,7 +50,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
protected override void OnClose()
{
// Remove all the attached appenders
- lock (this)
+ lock (LockObj)
{
_appenderAttachedImpl?.RemoveAllAppenders();
}
@@ -68,10 +66,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </para>
/// </remarks>
protected override void Append(LoggingEvent loggingEvent)
- {
- // Pass the logging event on to the attached appenders
- _appenderAttachedImpl?.AppendLoopOnAppenders(loggingEvent);
- }
+ => _appenderAttachedImpl?.AppendLoopOnAppenders(loggingEvent);
/// <summary>
/// Forward the logging events to the attached appenders
@@ -83,32 +78,26 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </para>
/// </remarks>
protected override void Append(LoggingEvent[] loggingEvents)
- {
- // Pass the logging event on to the attached appenders
- _appenderAttachedImpl?.AppendLoopOnAppenders(loggingEvents);
- }
+ => _appenderAttachedImpl?.AppendLoopOnAppenders(loggingEvents);
/// <summary>
/// Adds an <see cref="IAppender" /> to the list of appenders of this
/// instance.
/// </summary>
- /// <param name="newAppender">The <see cref="IAppender" /> to add to this appender.</param>
+ /// <param name="appender">The <see cref="IAppender" /> to add to this appender.</param>
/// <remarks>
/// <para>
/// If the specified <see cref="IAppender" /> is already in the list of
/// appenders, then it won't be added again.
/// </para>
/// </remarks>
- public virtual void AddAppender(IAppender newAppender)
+ public virtual void AddAppender(IAppender appender)
{
- if (newAppender is null)
- {
- throw new ArgumentNullException(nameof(newAppender));
- }
- lock (this)
+ appender.EnsureNotNull();
+ lock (LockObj)
{
- _appenderAttachedImpl ??= new AppenderAttachedImpl();
- _appenderAttachedImpl.AddAppender(newAppender);
+ _appenderAttachedImpl ??= new();
+ _appenderAttachedImpl.AddAppender(appender);
}
}
@@ -127,7 +116,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
{
get
{
- lock (this)
+ lock (LockObj)
{
return _appenderAttachedImpl?.Appenders ?? AppenderCollection.EmptyCollection;
}
@@ -148,7 +137,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </remarks>
public virtual IAppender? GetAppender(string? name)
{
- lock (this)
+ lock (LockObj)
{
if (_appenderAttachedImpl is null || name is null)
{
@@ -169,7 +158,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </remarks>
public virtual void RemoveAllAppenders()
{
- lock (this)
+ lock (LockObj)
{
if (_appenderAttachedImpl is not null)
{
@@ -191,7 +180,7 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </remarks>
public virtual IAppender? RemoveAppender(IAppender? appender)
{
- lock (this)
+ lock (LockObj)
{
if (appender is not null && _appenderAttachedImpl is not null)
{
@@ -213,11 +202,11 @@ public class ForwardingAppender : AppenderSkeleton, IAppenderAttachable
/// </remarks>
public virtual IAppender? RemoveAppender(string? name)
{
- lock (this)
+ lock (LockObj)
{
- if (name is not null && _appenderAttachedImpl is not null)
+ if (name is not null)
{
- return _appenderAttachedImpl.RemoveAppender(name);
+ return _appenderAttachedImpl?.RemoveAppender(name);
}
}
return null;
diff --git a/src/log4net/Appender/IAppender.cs b/src/log4net/Appender/IAppender.cs
index 6e769e8f..a3a75f86 100644
--- a/src/log4net/Appender/IAppender.cs
+++ b/src/log4net/Appender/IAppender.cs
@@ -31,7 +31,7 @@ namespace log4net.Appender;
/// </para>
/// <para>
/// Appenders can also implement the <see cref="IOptionHandler"/> interface. Therefore
-/// they would require that the <see cref="M:IOptionHandler.ActivateOptions()"/> method
+/// they would require that the <see cref="IOptionHandler.ActivateOptions()"/> method
/// be called after the appenders properties have been configured.
/// </para>
/// </remarks>
diff --git a/src/log4net/Appender/LocalSyslogAppender.cs b/src/log4net/Appender/LocalSyslogAppender.cs
index 8061d11b..6e6ead8d 100644
--- a/src/log4net/Appender/LocalSyslogAppender.cs
+++ b/src/log4net/Appender/LocalSyslogAppender.cs
@@ -318,7 +318,7 @@ public class LocalSyslogAppender : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
diff --git a/src/log4net/Appender/ManagedColoredConsoleAppender.cs b/src/log4net/Appender/ManagedColoredConsoleAppender.cs
index 91fcfc75..eeab8a9c 100644
--- a/src/log4net/Appender/ManagedColoredConsoleAppender.cs
+++ b/src/log4net/Appender/ManagedColoredConsoleAppender.cs
@@ -125,7 +125,7 @@ public class ManagedColoredConsoleAppender : AppenderSkeleton
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
/// <para>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)"/> method.
/// </para>
/// <para>
/// The format of the output will depend on the appender's layout.
diff --git a/src/log4net/Appender/MemoryAppender.cs b/src/log4net/Appender/MemoryAppender.cs
index c343dd70..b828f2a2 100644
--- a/src/log4net/Appender/MemoryAppender.cs
+++ b/src/log4net/Appender/MemoryAppender.cs
@@ -32,21 +32,21 @@ namespace log4net.Appender;
/// that are appended in an in-memory array.
/// </para>
/// <para>
-/// Use the <see cref="M:PopAllEvents()"/> method to get
+/// Use the <see cref="PopAllEvents()"/> method to get
/// and clear the current list of events that have been appended.
/// </para>
/// <para>
-/// Use the <see cref="M:GetEvents()"/> method to get the current
+/// Use the <see cref="GetEvents()"/> method to get the current
/// list of events that have been appended. Note there is a
-/// race-condition when calling <see cref="M:GetEvents()"/> and
-/// <see cref="M:Clear()"/> in pairs, you better use <see
+/// race-condition when calling <see cref="GetEvents()"/> and
+/// <see cref="Clear()"/> in pairs, you better use <see
/// mref="M:PopAllEvents()"/> in that case.
/// </para>
/// <para>
-/// Use the <see cref="M:Clear()"/> method to clear the
+/// Use the <see cref="Clear()"/> method to clear the
/// current list of events. Note there is a
-/// race-condition when calling <see cref="M:GetEvents()"/> and
-/// <see cref="M:Clear()"/> in pairs, you better use <see
+/// race-condition when calling <see cref="GetEvents()"/> and
+/// <see cref="Clear()"/> in pairs, you better use <see
/// mref="M:PopAllEvents()"/> in that case.
/// </para>
/// </remarks>
@@ -80,7 +80,7 @@ public class MemoryAppender : AppenderSkeleton
public virtual FixFlags Fix { get; set; } = FixFlags.All;
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">the event to log</param>
/// <remarks>
diff --git a/src/log4net/Appender/RemoteSyslogAppender.cs b/src/log4net/Appender/RemoteSyslogAppender.cs
index 06ce92b5..83661d6e 100644
--- a/src/log4net/Appender/RemoteSyslogAppender.cs
+++ b/src/log4net/Appender/RemoteSyslogAppender.cs
@@ -313,7 +313,7 @@ public class RemoteSyslogAppender : UdpAppender
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
/// <para>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </para>
/// <para>
/// The format of the output will depend on the appender's layout.
diff --git a/src/log4net/Appender/RollingFileAppender.cs b/src/log4net/Appender/RollingFileAppender.cs
index ebd15e9b..42f58f9e 100644
--- a/src/log4net/Appender/RollingFileAppender.cs
+++ b/src/log4net/Appender/RollingFileAppender.cs
@@ -564,7 +564,7 @@ public partial class RollingFileAppender : FileAppender
/// </remarks>
protected override void OpenFile(string fileName, bool append)
{
- lock (SyncRoot)
+ lock (LockObj)
{
fileName = GetNextOutputFileName(fileName);
@@ -576,7 +576,7 @@ public partial class RollingFileAppender : FileAppender
{
if (System.IO.File.Exists(fileName))
{
- currentCount = (new FileInfo(fileName)).Length;
+ currentCount = new FileInfo(fileName).Length;
}
}
}
@@ -1323,7 +1323,7 @@ public partial class RollingFileAppender : FileAppender
// Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
for (int i = CurrentSizeRollBackups; i >= 1; i--)
{
- RollFile((CombinePath(baseFileName, "." + i)), (CombinePath(baseFileName, "." + (i + 1))));
+ RollFile(CombinePath(baseFileName, "." + i), CombinePath(baseFileName, "." + (i + 1)));
}
CurrentSizeRollBackups++;
diff --git a/src/log4net/Appender/TextWriterAppender.cs b/src/log4net/Appender/TextWriterAppender.cs
index 05797811..e4d58ec4 100644
--- a/src/log4net/Appender/TextWriterAppender.cs
+++ b/src/log4net/Appender/TextWriterAppender.cs
@@ -139,7 +139,7 @@ public class TextWriterAppender : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/>
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/>
/// method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
@@ -168,7 +168,7 @@ public class TextWriterAppender : AppenderSkeleton
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent[])"/>
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent[])"/>
/// method.
/// </summary>
/// <param name="loggingEvents">The array of events to log.</param>
diff --git a/src/log4net/Appender/UdpAppender.cs b/src/log4net/Appender/UdpAppender.cs
index 04909048..cf4f03f9 100644
--- a/src/log4net/Appender/UdpAppender.cs
+++ b/src/log4net/Appender/UdpAppender.cs
@@ -313,31 +313,24 @@ public class UdpAppender : AppenderSkeleton
public override void ActivateOptions()
{
base.ActivateOptions();
+ RemoteAddress.EnsureNotNull();
- if (RemoteAddress is null)
+ if (RemotePort is < IPEndPoint.MinPort or > IPEndPoint.MaxPort)
{
- throw new ArgumentNullException(nameof(RemoteAddress), $"The required property '{nameof(RemoteAddress)}' was not specified.");
- }
-
- else if (RemotePort is < IPEndPoint.MinPort or > IPEndPoint.MaxPort)
- {
- throw Util.SystemInfo.CreateArgumentOutOfRangeException(nameof(RemotePort), RemotePort,
+ throw SystemInfo.CreateArgumentOutOfRangeException(nameof(RemotePort), RemotePort,
$"The RemotePort is less than {IPEndPoint.MinPort} or greater than {IPEndPoint.MaxPort}.");
}
- else if (LocalPort != 0 && (LocalPort < IPEndPoint.MinPort || this.LocalPort > IPEndPoint.MaxPort))
+ if (LocalPort is not 0 and (< IPEndPoint.MinPort or > IPEndPoint.MaxPort))
{
- throw Util.SystemInfo.CreateArgumentOutOfRangeException(nameof(LocalPort), LocalPort,
+ throw SystemInfo.CreateArgumentOutOfRangeException(nameof(LocalPort), LocalPort,
$"The LocalPort is less than {IPEndPoint.MinPort} or greater than {IPEndPoint.MaxPort}.");
}
- else
- {
- RemoteEndPoint = new(RemoteAddress, RemotePort);
- InitializeClientConnection();
- }
+ RemoteEndPoint = new(RemoteAddress, RemotePort);
+ InitializeClientConnection();
}
/// <summary>
- /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
+ /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
diff --git a/src/log4net/Config/BasicConfigurator.cs b/src/log4net/Config/BasicConfigurator.cs
index 4fc31bac..e0db7169 100644
--- a/src/log4net/Config/BasicConfigurator.cs
+++ b/src/log4net/Config/BasicConfigurator.cs
@@ -44,7 +44,7 @@ namespace log4net.Config;
/// </para>
/// <para>
/// Appenders can also implement the <see cref="log4net.Core.IOptionHandler"/> interface. Therefore
-/// they would require that the <see cref="M:log4net.Core.IOptionHandler.ActivateOptions()"/> method
+/// they would require that the <see cref="log4net.Core.IOptionHandler.ActivateOptions()"/> method
/// be called after the appenders properties have been configured.
/// </para>
/// </remarks>
diff --git a/src/log4net/Config/PluginAttribute.cs b/src/log4net/Config/PluginAttribute.cs
index 56c637a8..c0cca5cd 100644
--- a/src/log4net/Config/PluginAttribute.cs
+++ b/src/log4net/Config/PluginAttribute.cs
@@ -72,6 +72,7 @@ public sealed class PluginAttribute : Attribute, IPluginFactory
/// <summary>
/// Gets or sets the type for the plugin.
/// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
public Type? Type { get; set; }
/// <summary>
@@ -82,6 +83,7 @@ public sealed class PluginAttribute : Attribute, IPluginFactory
/// Where possible use the <see cref="Type"/> property instead.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
public string? TypeName { get; set; }
/// <summary>
diff --git a/src/log4net/Config/RepositoryAttribute.cs b/src/log4net/Config/RepositoryAttribute.cs
index 633a506e..ab530bca 100644
--- a/src/log4net/Config/RepositoryAttribute.cs
+++ b/src/log4net/Config/RepositoryAttribute.cs
@@ -54,8 +54,7 @@ public sealed class RepositoryAttribute : Attribute
/// </para>
/// </remarks>
public RepositoryAttribute()
- {
- }
+ { }
/// <summary>
/// Initialize a new instance of the <see cref="RepositoryAttribute" /> class
@@ -67,10 +66,7 @@ public sealed class RepositoryAttribute : Attribute
/// Initialize the attribute with the name for the assembly's repository.
/// </para>
/// </remarks>
- public RepositoryAttribute(string name)
- {
- Name = name;
- }
+ public RepositoryAttribute(string name) => Name = name;
/// <summary>
/// Gets or sets the name of the logging repository.
@@ -85,6 +81,7 @@ public sealed class RepositoryAttribute : Attribute
/// same repository. They will share the logging configuration of the repository.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
public string? Name { get; set; }
/// <summary>
diff --git a/src/log4net/Config/SecurityContextProviderAttribute.cs b/src/log4net/Config/SecurityContextProviderAttribute.cs
index 2c813483..1e60ebf3 100644
--- a/src/log4net/Config/SecurityContextProviderAttribute.cs
+++ b/src/log4net/Config/SecurityContextProviderAttribute.cs
@@ -29,6 +29,7 @@ namespace log4net.Config;
/// <summary>
/// Assembly level attribute to configure the <see cref="SecurityContextProvider"/>.
/// </summary>
+/// <param name="providerType">the type of the provider to use</param>
/// <remarks>
/// <para>
/// This attribute may only be used at the assembly scope and can only
@@ -36,30 +37,16 @@ namespace log4net.Config;
/// </para>
/// <para>
/// Use this attribute to configure the <see cref="XmlConfigurator"/>
-/// without calling one of the <see cref="M:XmlConfigurator.Configure()"/>
+/// without calling one of the <see cref="XmlConfigurator.Configure()"/>
/// methods.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
[AttributeUsage(AttributeTargets.Assembly)]
[Log4NetSerializable]
-public sealed class SecurityContextProviderAttribute : ConfiguratorAttribute
+public sealed class SecurityContextProviderAttribute(Type providerType)
+ : ConfiguratorAttribute(100)
{
- /// <summary>
- /// Construct provider attribute with type specified
- /// </summary>
- /// <param name="providerType">the type of the provider to use</param>
- /// <remarks>
- /// <para>
- /// The provider specified must subclass the <see cref="SecurityContextProvider"/>
- /// class.
- /// </para>
- /// </remarks>
- public SecurityContextProviderAttribute(Type providerType) : base(100) /* configurator priority 100 to execute before the XmlConfigurator */
- {
- ProviderType = providerType;
- }
-
/// <summary>
/// Gets or sets the type of the provider to use.
/// </summary>
@@ -69,7 +56,8 @@ public sealed class SecurityContextProviderAttribute : ConfiguratorAttribute
/// class.
/// </para>
/// </remarks>
- public Type ProviderType { get; set; }
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
+ public Type ProviderType { get; set; } = providerType;
/// <summary>
/// Configures the SecurityContextProvider
@@ -107,8 +95,7 @@ public sealed class SecurityContextProviderAttribute : ConfiguratorAttribute
/// The fully qualified type of the SecurityContextProviderAttribute class.
/// </summary>
/// <remarks>
- /// Used by the internal logger to record the Type of the
- /// log message.
+ /// Used by the internal logger to record the Type of the log message.
/// </remarks>
private static readonly Type _declaringType = typeof(SecurityContextProviderAttribute);
-}
+}
\ No newline at end of file
diff --git a/src/log4net/Config/XmlConfigurator.cs b/src/log4net/Config/XmlConfigurator.cs
index 2b78786e..bf7f4315 100644
--- a/src/log4net/Config/XmlConfigurator.cs
+++ b/src/log4net/Config/XmlConfigurator.cs
@@ -636,10 +636,10 @@ public static class XmlConfigurator
/// </para>
/// <para>
/// For more information on how to configure log4net using
- /// a separate configuration file, see <see cref="M:Configure(FileInfo)"/>.
+ /// a separate configuration file, see <see cref="Configure(FileInfo)"/>.
/// </para>
/// </remarks>
- /// <seealso cref="M:Configure(FileInfo)"/>
+ /// <seealso cref="Configure(FileInfo)"/>
public static ICollection ConfigureAndWatch(FileInfo configFile)
{
List<LogLog> configurationMessages = [];
@@ -675,10 +675,10 @@ public static class XmlConfigurator
/// </para>
/// <para>
/// For more information on how to configure log4net using
- /// a separate configuration file, see <see cref="M:Configure(FileInfo)"/>.
+ /// a separate configuration file, see <see cref="Configure(FileInfo)"/>.
/// </para>
/// </remarks>
- /// <seealso cref="M:Configure(FileInfo)"/>
+ /// <seealso cref="Configure(FileInfo)"/>
public static ICollection ConfigureAndWatch(ILoggerRepository repository, FileInfo configFile)
{
repository.EnsureNotNull();
diff --git a/src/log4net/Config/XmlConfiguratorAttribute.cs b/src/log4net/Config/XmlConfiguratorAttribute.cs
index 2f3d0f84..0bf39053 100644
--- a/src/log4net/Config/XmlConfiguratorAttribute.cs
+++ b/src/log4net/Config/XmlConfiguratorAttribute.cs
@@ -38,7 +38,7 @@ namespace log4net.Config;
/// </para>
/// <para>
/// Use this attribute to configure the <see cref="XmlConfigurator"/>
-/// without calling one of the <see cref="M:XmlConfigurator.Configure()"/>
+/// without calling one of the <see cref="XmlConfigurator.Configure()"/>
/// methods.
/// </para>
/// <para>
@@ -69,7 +69,7 @@ namespace log4net.Config;
/// <para>
/// If you cannot guarantee the order in which log4net calls will be made from
/// different assemblies you must use programmatic configuration instead, i.e.
-/// call the <see cref="M:XmlConfigurator.Configure()"/> method directly.
+/// call the <see cref="XmlConfigurator.Configure()"/> method directly.
/// </para>
/// </note>
/// </remarks>
@@ -185,7 +185,7 @@ public sealed class XmlConfiguratorAttribute : ConfiguratorAttribute
// and the application does not have PathDiscovery permission
}
- if (applicationBaseDirectory is null || (new Uri(applicationBaseDirectory)).IsFile)
+ if (applicationBaseDirectory is null || new Uri(applicationBaseDirectory).IsFile)
{
ConfigureFromFile(sourceAssembly, targetRepository);
}
diff --git a/src/log4net/Core/DefaultRepositorySelector.cs b/src/log4net/Core/DefaultRepositorySelector.cs
index 6122e9d1..f960a6e4 100644
--- a/src/log4net/Core/DefaultRepositorySelector.cs
+++ b/src/log4net/Core/DefaultRepositorySelector.cs
@@ -122,7 +122,7 @@ public class DefaultRepositorySelector : IRepositorySelector
/// does not exist a <see cref="LogException"/> is thrown.
/// </para>
/// <para>
- /// Use <see cref="M:CreateRepository(string, Type)"/> to create a repository.
+ /// Use <see cref="CreateRepository(string, Type)"/> to create a repository.
/// </para>
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="repositoryName"/> is <see langword="null" />.</exception>
@@ -148,7 +148,7 @@ public class DefaultRepositorySelector : IRepositorySelector
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository(Assembly)"/> with the
+ /// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// <para>
@@ -189,7 +189,7 @@ public class DefaultRepositorySelector : IRepositorySelector
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository(Assembly)"/> with the
+ /// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// <para>
@@ -299,7 +299,7 @@ public class DefaultRepositorySelector : IRepositorySelector
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository(string)"/> with the
+ /// specified such that a call to <see cref="GetRepository(string)"/> with the
/// same repository specified will return the same repository instance.
/// </para>
/// </remarks>
@@ -375,8 +375,8 @@ public class DefaultRepositorySelector : IRepositorySelector
/// <returns><c>true</c> if the repository exists</returns>
/// <remarks>
/// <para>
- /// Test if a named repository exists. Use <see cref="M:CreateRepository(string, Type)"/>
- /// to create a new repository and <see cref="M:GetRepository(string)"/> to retrieve
+ /// Test if a named repository exists. Use <see cref="CreateRepository(string, Type)"/>
+ /// to create a new repository and <see cref="GetRepository(string)"/> to retrieve
/// a repository.
/// </para>
/// </remarks>
diff --git a/src/log4net/Core/ErrorCode.cs b/src/log4net/Core/ErrorCode.cs
index 839d91a6..c936b64e 100644
--- a/src/log4net/Core/ErrorCode.cs
+++ b/src/log4net/Core/ErrorCode.cs
@@ -17,14 +17,16 @@
//
#endregion
+using System;
+
namespace log4net.Core;
/// <summary>
-/// Defined error codes that can be passed to the <see cref="M:IErrorHandler.Error(string, Exception, ErrorCode)"/> method.
+/// Defined error codes that can be passed to the <see cref="IErrorHandler.Error(string, Exception, ErrorCode)"/> method.
/// </summary>
/// <remarks>
/// <para>
-/// Values passed to the <see cref="M:IErrorHandler.Error(string, Exception, ErrorCode)"/> method.
+/// Values passed to the <see cref="IErrorHandler.Error(string, Exception, ErrorCode)"/> method.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
diff --git a/src/log4net/Core/ExceptionEvaluator.cs b/src/log4net/Core/ExceptionEvaluator.cs
index be4824bc..5fd50882 100644
--- a/src/log4net/Core/ExceptionEvaluator.cs
+++ b/src/log4net/Core/ExceptionEvaluator.cs
@@ -17,6 +17,7 @@
//
#endregion
+using log4net.Util;
using System;
namespace log4net.Core;
@@ -27,7 +28,7 @@ namespace log4net.Core;
/// <remarks>
/// <para>
/// This evaluator will trigger if the type of the Exception
-/// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
+/// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is equal to a Type in <see cref="ExceptionType"/>. ///
/// </para>
/// </remarks>
@@ -49,12 +50,7 @@ public class ExceptionEvaluator : ITriggeringEventEvaluator
/// <param name="triggerOnSubClass">If true, this evaluator will trigger on subclasses of <see cref="ExceptionType"/>.</param>
public ExceptionEvaluator(Type exType, bool triggerOnSubClass)
{
- if (exType is null)
- {
- throw new ArgumentNullException(nameof(exType));
- }
-
- ExceptionType = exType;
+ ExceptionType = exType.EnsureNotNull();
TriggerOnSubclass = triggerOnSubClass;
}
@@ -78,32 +74,25 @@ public class ExceptionEvaluator : ITriggeringEventEvaluator
/// <remarks>
/// <para>
/// This evaluator will trigger if the Exception Type of the event
- /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
+ /// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is <see cref="ExceptionType"/>.
/// </para>
/// </remarks>
public bool IsTriggeringEvent(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
+ loggingEvent.EnsureNotNull();
if (TriggerOnSubclass && loggingEvent.ExceptionObject is not null)
{
// check if loggingEvent.ExceptionObject is of type ExceptionType or subclass of ExceptionType
Type exceptionObjectType = loggingEvent.ExceptionObject.GetType();
return ExceptionType is null || exceptionObjectType == ExceptionType || ExceptionType.IsAssignableFrom(exceptionObjectType);
}
- else if (!TriggerOnSubclass && loggingEvent.ExceptionObject is not null)
+ if (!TriggerOnSubclass && loggingEvent.ExceptionObject is not null)
{
// check if loggingEvent.ExceptionObject is of type ExceptionType
return loggingEvent.ExceptionObject.GetType() == ExceptionType;
}
- else
- {
- // loggingEvent.ExceptionObject is null
- return false;
- }
+ // loggingEvent.ExceptionObject is null
+ return false;
}
}
diff --git a/src/log4net/Core/FixFlags.cs b/src/log4net/Core/FixFlags.cs
index 35edacd3..833e50c3 100644
--- a/src/log4net/Core/FixFlags.cs
+++ b/src/log4net/Core/FixFlags.cs
@@ -26,6 +26,8 @@ namespace log4net.Core;
/// </summary>
/// <author>Nicko Cadell</author>
[Flags]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2217:Do not mark enums with FlagsAttribute")]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public enum FixFlags
{
/// <summary>
diff --git a/src/log4net/Core/IErrorHandler.cs b/src/log4net/Core/IErrorHandler.cs
index 444fb6f8..c9b30054 100644
--- a/src/log4net/Core/IErrorHandler.cs
+++ b/src/log4net/Core/IErrorHandler.cs
@@ -56,7 +56,7 @@ public interface IErrorHandler
/// <param name="e">The <see cref="Exception" /> that was thrown when the error occurred.</param>
/// <remarks>
/// <para>
- /// See <see cref="M:Error(string,Exception,ErrorCode)"/>.
+ /// See <see cref="Error(string,Exception,ErrorCode)"/>.
/// </para>
/// </remarks>
void Error(string message, Exception e);
@@ -67,7 +67,7 @@ public interface IErrorHandler
/// <param name="message">The message associated with the error.</param>
/// <remarks>
/// <para>
- /// See <see cref="M:Error(string,Exception,ErrorCode)"/>.
+ /// See <see cref="Error(string,Exception,ErrorCode)"/>.
/// </para>
/// </remarks>
void Error(string message);
diff --git a/src/log4net/Core/IRepositorySelector.cs b/src/log4net/Core/IRepositorySelector.cs
index 893d5dc6..d5ff2cad 100644
--- a/src/log4net/Core/IRepositorySelector.cs
+++ b/src/log4net/Core/IRepositorySelector.cs
@@ -35,33 +35,22 @@ namespace log4net.Core;
/// Delegate used to handle logger repository creation event notifications.
/// </para>
/// </remarks>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1003:Use generic event handler instances")]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public delegate void LoggerRepositoryCreationEventHandler(object sender, LoggerRepositoryCreationEventArgs e);
/// <summary>
/// Provides data for the <see cref="IRepositorySelector.LoggerRepositoryCreatedEvent"/> event.
/// </summary>
+/// <param name="repository">the <see cref="ILoggerRepository"/> that has been created</param>
/// <remarks>
/// <para>
/// A <see cref="IRepositorySelector.LoggerRepositoryCreatedEvent"/>
/// event is raised every time a <see cref="ILoggerRepository"/> is created.
/// </para>
/// </remarks>
-public class LoggerRepositoryCreationEventArgs : EventArgs
+public class LoggerRepositoryCreationEventArgs(ILoggerRepository repository) : EventArgs
{
- /// <summary>
- /// Construct instance using <see cref="ILoggerRepository"/> specified
- /// </summary>
- /// <param name="repository">the <see cref="ILoggerRepository"/> that has been created</param>
- /// <remarks>
- /// <para>
- /// Construct instance using <see cref="ILoggerRepository"/> specified
- /// </para>
- /// </remarks>
- public LoggerRepositoryCreationEventArgs(ILoggerRepository repository)
- {
- LoggerRepository = repository;
- }
-
/// <summary>
/// The <see cref="ILoggerRepository"/> that has been created
/// </summary>
@@ -73,7 +62,7 @@ public class LoggerRepositoryCreationEventArgs : EventArgs
/// The <see cref="ILoggerRepository"/> that has been created
/// </para>
/// </remarks>
- public ILoggerRepository LoggerRepository { get; }
+ public ILoggerRepository LoggerRepository { get; } = repository;
}
/// <summary>
@@ -116,7 +105,7 @@ public interface IRepositorySelector
/// <returns>The named <see cref="ILoggerRepository"/></returns>
/// <remarks>
/// Lookup a named <see cref="ILoggerRepository"/>. This is the repository created by
- /// calling <see cref="M:CreateRepository(string,Type)"/>.
+ /// calling <see cref="CreateRepository(string,Type)"/>.
/// </remarks>
ILoggerRepository GetRepository(string repositoryName);
@@ -129,7 +118,7 @@ public interface IRepositorySelector
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the domain
- /// specified such that a call to <see cref="M:GetRepository(Assembly)"/> with the
+ /// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// <para>
@@ -149,7 +138,7 @@ public interface IRepositorySelector
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the name
- /// specified such that a call to <see cref="M:GetRepository(string)"/> with the
+ /// specified such that a call to <see cref="GetRepository(string)"/> with the
/// same name will return the same repository instance.
/// </para>
/// </remarks>
@@ -162,8 +151,8 @@ public interface IRepositorySelector
/// <returns><c>true</c> if the repository exists</returns>
/// <remarks>
/// <para>
- /// Test if a named repository exists. Use <see cref="M:CreateRepository(Assembly, Type)"/>
- /// to create a new repository and <see cref="M:GetRepository(Assembly)"/> to retrieve
+ /// Test if a named repository exists. Use <see cref="CreateRepository(Assembly, Type)"/>
+ /// to create a new repository and <see cref="GetRepository(Assembly)"/> to retrieve
/// a repository.
/// </para>
/// </remarks>
diff --git a/src/log4net/Core/Level.cs b/src/log4net/Core/Level.cs
index badb6552..6023176c 100644
--- a/src/log4net/Core/Level.cs
+++ b/src/log4net/Core/Level.cs
@@ -130,10 +130,11 @@ public class Level : IComparable, ILog4NetSerializable, IEquatable<Level>, IComp
/// with serialized data.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter")]
protected Level(SerializationInfo info, StreamingContext context)
{
// Use member names from log4net 2.x implicit serialzation for cross-version compat.
- Value = info.GetInt32("m_levelValue");
+ Value = info.EnsureNotNull().GetInt32("m_levelValue");
Name = info.GetString("m_levelName") ?? string.Empty;
DisplayName = info.GetString("m_levelDisplayName") ?? string.Empty;
}
@@ -176,7 +177,7 @@ public class Level : IComparable, ILog4NetSerializable, IEquatable<Level>, IComp
public override string ToString() => Name;
/// <inheritdoc cref="Equals(Level)"/>
- public override bool Equals(object? o) => o is Level level && Equals(level);
+ public override bool Equals(object? obj) => obj is Level level && Equals(level);
/// <summary>
/// Compares levels.
@@ -201,7 +202,7 @@ public class Level : IComparable, ILog4NetSerializable, IEquatable<Level>, IComp
public override int GetHashCode() => Value;
/// <inheritdoc cref="CompareTo(Level)"/>
- public int CompareTo(object? r) => Compare(this, r.EnsureIs<Level>());
+ public int CompareTo(object? obj) => Compare(this, obj.EnsureIs<Level>());
/// <summary>
/// Compares this instance to a specified object and returns an
@@ -253,7 +254,7 @@ public class Level : IComparable, ILog4NetSerializable, IEquatable<Level>, IComp
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
// Use member names from log4net 2.x implicit serialzation for cross-version compat.
- info.AddValue("m_levelValue", Value);
+ info.EnsureNotNull().AddValue("m_levelValue", Value);
info.AddValue("m_levelName", Name);
info.AddValue("m_levelDisplayName", DisplayName);
}
diff --git a/src/log4net/Core/LevelCollection.cs b/src/log4net/Core/LevelCollection.cs
index 269600b3..9196d50b 100644
--- a/src/log4net/Core/LevelCollection.cs
+++ b/src/log4net/Core/LevelCollection.cs
@@ -92,44 +92,48 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// Initializes a new instance of the <c>LevelCollection</c> class
/// that contains elements copied from the specified <c>LevelCollection</c>.
/// </summary>
- /// <param name="c">The <c>LevelCollection</c> whose elements are copied to the new collection.</param>
- public LevelCollection(LevelCollection c)
+ /// <param name="collection">The <c>LevelCollection</c> whose elements are copied to the new collection.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public LevelCollection(LevelCollection collection)
{
- _array = new Level[c.Count];
- AddRange(c);
+ _array = new Level[collection.EnsureNotNull().Count];
+ AddRange(collection);
}
/// <summary>
/// Initializes a new instance of the <c>LevelCollection</c> class
/// that contains elements copied from the specified <see cref="Level"/> array.
/// </summary>
- /// <param name="a">The <see cref="Level"/> array whose elements are copied to the new list.</param>
- public LevelCollection(Level[] a)
+ /// <param name="array">The <see cref="Level"/> array whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public LevelCollection(Level[] array)
{
- _array = new Level[a.Length];
- AddRange(a);
+ _array = new Level[array.EnsureNotNull().Length];
+ AddRange(array);
}
/// <summary>
/// Initializes a new instance of the <c>LevelCollection</c> class
/// that contains elements copied from the specified <see cref="Level"/> collection.
/// </summary>
- /// <param name="col">The <see cref="Level"/> collection whose elements are copied to the new list.</param>
- public LevelCollection(ICollection col)
+ /// <param name="collection">The <see cref="Level"/> collection whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public LevelCollection(ICollection collection)
{
- _array = new Level[col.Count];
- AddRange(col);
+ _array = new Level[collection.EnsureNotNull().Count];
+ AddRange(collection);
}
/// <summary>
/// Initializes a new instance of the <c>LevelCollection</c> class
/// that contains elements copied from the specified <see cref="Level"/> collection.
/// </summary>
- /// <param name="col">The <see cref="Level"/> collection whose elements are copied to the new list.</param>
- public LevelCollection(ICollection<Level> col)
+ /// <param name="collection">The <see cref="Level"/> collection whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public LevelCollection(ICollection<Level> collection)
{
- _array = new Level[col.Count];
- AddRange((ICollection)col);
+ _array = new Level[collection.EnsureNotNull().Count];
+ AddRange((ICollection)collection);
}
/// <summary>
@@ -147,10 +151,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Allow subclasses to avoid our default constructors
/// </summary>
- protected internal LevelCollection(Tag _)
- {
- _array = Array.Empty<Level>();
- }
+ protected internal LevelCollection(Tag _) => _array = Array.Empty<Level>();
/// <summary>
/// Gets the number of elements actually contained in the <c>LevelCollection</c>.
@@ -162,7 +163,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <see cref="Level"/> array.
/// </summary>
/// <param name="array">The one-dimensional <see cref="Level"/> array to copy to.</param>
- public virtual void CopyTo(Level[] array) => this.CopyTo(array, 0);
+ public virtual void CopyTo(Level[] array) => CopyTo(array, 0);
/// <summary>
/// Copies the entire <c>LevelCollection</c> to a one-dimensional
@@ -172,12 +173,12 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
public virtual void CopyTo(Level[] array, int start)
{
- if (Count > array.GetUpperBound(0) + 1 - start)
+ if (Count > array.EnsureNotNull().GetUpperBound(0) + 1 - start)
{
throw new ArgumentException("Destination array was not long enough.");
}
- Array.Copy(this._array, 0, array, start, Count);
+ Array.Copy(_array, 0, array, start, Count);
}
/// <summary>
@@ -198,7 +199,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual Level this[int index]
{
@@ -303,7 +304,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual void Insert(int index, Level item)
{
@@ -336,7 +337,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
int i = IndexOf(item);
if (i < 0)
{
- throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
+ throw new ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
}
++_version;
@@ -350,7 +351,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual void RemoveAt(int index)
{
@@ -394,10 +395,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// </summary>
public virtual int Capacity
{
- get
- {
- return _array.Length;
- }
+ get => _array.Length;
set
{
if (value < Count)
@@ -424,17 +422,17 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of another <c>LevelCollection</c> to the current <c>LevelCollection</c>.
/// </summary>
- /// <param name="x">The <c>LevelCollection</c> whose elements should be added to the end of the current <c>LevelCollection</c>.</param>
- /// <returns>The new <see cref="LevelCollection.Count"/> of the <c>LevelCollection</c>.</returns>
- public virtual int AddRange(LevelCollection x)
+ /// <param name="collection">The <c>LevelCollection</c> whose elements should be added to the end of the current <c>LevelCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>LevelCollection</c>.</returns>
+ public virtual int AddRange(LevelCollection collection)
{
- if (Count + x.Count >= _array.Length)
+ if (Count + collection.EnsureNotNull().Count >= _array.Length)
{
- EnsureCapacity(Count + x.Count);
+ EnsureCapacity(Count + collection.Count);
}
- Array.Copy(x._array, 0, _array, Count, x.Count);
- Count += x.Count;
+ Array.Copy(collection._array, 0, _array, Count, collection.Count);
+ Count += collection.Count;
_version++;
return Count;
@@ -443,17 +441,17 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of a <see cref="Level"/> array to the current <c>LevelCollection</c>.
/// </summary>
- /// <param name="x">The <see cref="Level"/> array whose elements should be added to the end of the <c>LevelCollection</c>.</param>
- /// <returns>The new <see cref="LevelCollection.Count"/> of the <c>LevelCollection</c>.</returns>
- public virtual int AddRange(Level[] x)
+ /// <param name="array">The <see cref="Level"/> array whose elements should be added to the end of the <c>LevelCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>LevelCollection</c>.</returns>
+ public virtual int AddRange(Level[] array)
{
- if (Count + x.Length >= _array.Length)
+ if (Count + array.EnsureNotNull().Length >= _array.Length)
{
- EnsureCapacity(Count + x.Length);
+ EnsureCapacity(Count + array.Length);
}
- Array.Copy(x, 0, _array, Count, x.Length);
- Count += x.Length;
+ Array.Copy(array, 0, _array, Count, array.Length);
+ Count += array.Length;
_version++;
return Count;
@@ -462,16 +460,16 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of a <see cref="Level"/> collection to the current <c>LevelCollection</c>.
/// </summary>
- /// <param name="col">The <see cref="Level"/> collection whose elements should be added to the end of the <c>LevelCollection</c>.</param>
- /// <returns>The new <see cref="LevelCollection.Count"/> of the <c>LevelCollection</c>.</returns>
- public virtual int AddRange(ICollection col)
+ /// <param name="collection">The <see cref="Level"/> collection whose elements should be added to the end of the <c>LevelCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>LevelCollection</c>.</returns>
+ public virtual int AddRange(ICollection collection)
{
- if (Count + col.Count >= _array.Length)
+ if (Count + collection.EnsureNotNull().Count >= _array.Length)
{
- EnsureCapacity(Count + col.Count);
+ EnsureCapacity(Count + collection.Count);
}
- foreach (object item in col)
+ foreach (object item in collection)
{
Add((Level)item);
}
@@ -487,27 +485,28 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="i"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="i"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
+ /// <para><paramref name="i"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
private void ValidateIndex(int i) => ValidateIndex(i, false);
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="i"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="i"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
+ /// <para><paramref name="i"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
private void ValidateIndex(int i, bool allowEqualEnd)
{
- int max = (allowEqualEnd) ? (Count) : (Count - 1);
+ int max = allowEqualEnd ? Count : (Count - 1);
if (i < 0 || i > max)
{
- throw log4net.Util.SystemInfo.CreateArgumentOutOfRangeException(nameof(i), i, $"Index was out of range. Must be non-negative and less than the size of the collection. [{i}] Specified argument was out of the range of valid values.");
+ throw SystemInfo.CreateArgumentOutOfRangeException(nameof(i), i,
+ $"Index was out of range. Must be non-negative and less than the size of the collection. [{i}] Specified argument was out of the range of valid values.");
}
}
private void EnsureCapacity(int min)
{
- int newCapacity = ((_array.Length == 0) ? DefaultCapacity : _array.Length * 2);
+ int newCapacity = (_array.Length == 0) ? DefaultCapacity : _array.Length * 2;
if (newCapacity < min)
{
newCapacity = min;
@@ -516,7 +515,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
Capacity = newCapacity;
}
- void ICollection.CopyTo(Array array, int start) => Array.Copy(this._array, 0, array, start, Count);
+ void ICollection.CopyTo(Array array, int start) => Array.Copy(_array, 0, array, start, Count);
object? IList.this[int i]
{
@@ -581,7 +580,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
}
++_index;
- return (_index < _collection.Count);
+ return _index < _collection.Count;
}
/// <summary>
@@ -596,10 +595,7 @@ public class LevelCollection : ICollection, IList, IEnumerable, ICloneable
{
private readonly LevelCollection _collection;
- internal ReadOnlyLevelCollection(LevelCollection list) : base(Tag.Default)
- {
- _collection = list;
- }
+ internal ReadOnlyLevelCollection(LevelCollection list) : base(Tag.Default) => _collection = list;
public override void CopyTo(Level[] array) => _collection.CopyTo(array);
diff --git a/src/log4net/Core/LevelEvaluator.cs b/src/log4net/Core/LevelEvaluator.cs
index e811f758..da056ff5 100644
--- a/src/log4net/Core/LevelEvaluator.cs
+++ b/src/log4net/Core/LevelEvaluator.cs
@@ -17,23 +17,24 @@
//
#endregion
-using System;
+using log4net.Util;
namespace log4net.Core;
/// <summary>
/// An evaluator that triggers at a threshold level
/// </summary>
+/// <param name="threshold">the threshold to trigger at</param>
/// <remarks>
/// <para>
/// This evaluator will trigger if the level of the event
-/// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
+/// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is equal to or greater than the <see cref="Threshold"/>
/// level.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
-public class LevelEvaluator : ITriggeringEventEvaluator
+public class LevelEvaluator(Level threshold) : ITriggeringEventEvaluator
{
/// <summary>
/// Create a new evaluator using the <see cref="Level.Off"/> threshold.
@@ -41,36 +42,14 @@ public class LevelEvaluator : ITriggeringEventEvaluator
/// <remarks>
/// <para>
/// This evaluator will trigger if the level of the event
- /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
+ /// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is equal to or greater than the <see cref="Threshold"/>
/// level.
/// </para>
/// </remarks>
- public LevelEvaluator() : this(Level.Off)
- {
- }
-
- /// <summary>
- /// Create a new evaluator using the specified <see cref="Level"/> threshold.
- /// </summary>
- /// <param name="threshold">the threshold to trigger at</param>
- /// <remarks>
- /// <para>
- /// This evaluator will trigger if the level of the event
- /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
- /// is equal to or greater than the <see cref="Threshold"/>
- /// level.
- /// </para>
- /// </remarks>
- public LevelEvaluator(Level threshold)
- {
- if (threshold is null)
- {
- throw new ArgumentNullException(nameof(threshold));
- }
-
- Threshold = threshold;
- }
+ public LevelEvaluator()
+ : this(Level.Off)
+ { }
/// <summary>
/// the threshold to trigger at
@@ -81,12 +60,12 @@ public class LevelEvaluator : ITriggeringEventEvaluator
/// <remarks>
/// <para>
/// This evaluator will trigger if the level of the event
- /// passed to <see cref="M:IsTriggeringEvent(LoggingEvent)"/>
+ /// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is equal to or greater than the <see cref="Threshold"/>
/// level.
/// </para>
/// </remarks>
- public Level Threshold { get; set; }
+ public Level Threshold { get; set; } = threshold.EnsureNotNull();
/// <summary>
/// Is this <paramref name="loggingEvent"/> the triggering event?
@@ -96,12 +75,5 @@ public class LevelEvaluator : ITriggeringEventEvaluator
/// is equal or higher than the <see cref="Threshold"/>.
/// Otherwise it returns <c>false</c></returns>
public bool IsTriggeringEvent(LoggingEvent loggingEvent)
- {
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
- return (loggingEvent.Level is null || loggingEvent.Level >= Threshold);
- }
+ => loggingEvent.EnsureNotNull().Level is null || loggingEvent.Level >= Threshold;
}
diff --git a/src/log4net/Core/LevelMap.cs b/src/log4net/Core/LevelMap.cs
index aac2f8ec..485af58c 100644
--- a/src/log4net/Core/LevelMap.cs
+++ b/src/log4net/Core/LevelMap.cs
@@ -49,11 +49,9 @@ public sealed class LevelMap
/// Clear the internal maps of all levels
/// </para>
/// </remarks>
- public void Clear()
- {
+ public void Clear() =>
// Clear all current levels
_mapName2Level.Clear();
- }
/// <summary>
/// Looks up a <see cref="Level"/> by name
@@ -64,12 +62,7 @@ public sealed class LevelMap
{
get
{
- if (name is null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- _mapName2Level.TryGetValue(name, out Level? level);
+ _mapName2Level.TryGetValue(name.EnsureNotNull(), out Level? level);
return level;
}
}
@@ -79,11 +72,8 @@ public sealed class LevelMap
/// </summary>
/// <param name="name">the string to display for the Level</param>
/// <param name="value">the level value to give to the Level</param>
- /// <seealso cref="M:Add(string,int,string)"/>
- public void Add(string name, int value)
- {
- Add(name, value, null);
- }
+ /// <seealso cref="Add(string,int,string)"/>
+ public void Add(string name, int value) => Add(name, value, null);
/// <summary>
/// Creates a new Level and adds it to the map.
@@ -93,13 +83,10 @@ public sealed class LevelMap
/// <param name="displayName">the display name to give to the Level</param>
public void Add(string name, int value, string? displayName)
{
- if (name is null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (name.Length == 0)
+ if (name.EnsureNotNull().Length == 0)
{
- throw SystemInfo.CreateArgumentOutOfRangeException(nameof(name), name, $"Parameter: name, Value: [{name}] out of range. Level name must not be empty");
+ throw SystemInfo.CreateArgumentOutOfRangeException(nameof(name), name,
+ $"Parameter: name, Value: [{name}] out of range. Level name must not be empty");
}
if (string.IsNullOrEmpty(displayName))
@@ -114,14 +101,7 @@ public sealed class LevelMap
/// Adds a Level to the map.
/// </summary>
/// <param name="level">the Level to add</param>
- public void Add(Level level)
- {
- if (level is null)
- {
- throw new ArgumentNullException(nameof(level));
- }
- _mapName2Level[level.Name] = level;
- }
+ public void Add(Level level) => _mapName2Level[level.EnsureNotNull().Name] = level;
/// <summary>
/// Gets all possible levels as a collection of Level objects.
@@ -139,13 +119,6 @@ public sealed class LevelMap
/// and returned.
/// </param>
/// <returns>the level in the map with the name specified</returns>
- public Level LookupWithDefault(Level defaultLevel)
- {
- if (defaultLevel is null)
- {
- throw new ArgumentNullException(nameof(defaultLevel));
- }
-
- return _mapName2Level.GetOrAdd(defaultLevel.Name, defaultLevel);
- }
+ public Level LookupWithDefault(Level defaultLevel)
+ => _mapName2Level.GetOrAdd(defaultLevel.EnsureNotNull().Name, defaultLevel);
}
diff --git a/src/log4net/Core/LocationInfo.cs b/src/log4net/Core/LocationInfo.cs
index de69cfea..0d30baaf 100644
--- a/src/log4net/Core/LocationInfo.cs
+++ b/src/log4net/Core/LocationInfo.cs
@@ -84,7 +84,7 @@ public class LocationInfo : ILog4NetSerializable
{
try
{
- StackTrace st = new StackTrace(true);
+ StackTrace st = new(true);
int frameIndex = 0;
// skip frames not from fqnOfCallingClass
@@ -186,10 +186,11 @@ public class LocationInfo : ILog4NetSerializable
/// with serialized data.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter")]
protected LocationInfo(SerializationInfo info, StreamingContext context)
{
// Use member names from log4net 2.x implicit serialzation for cross-version compat.
- ClassName = info.GetString("m_className");
+ ClassName = info.EnsureNotNull().GetString("m_className");
FileName = info.GetString("m_fileName");
LineNumber = info.GetString("m_lineNumber") ?? string.Empty;
MethodName = info.GetString("m_methodName") ?? string.Empty;
@@ -225,17 +226,12 @@ public class LocationInfo : ILog4NetSerializable
/// All available caller information, in the format
/// <c>fully.qualified.classname.of.caller.methodName(Filename:line)</c>
/// </value>
- /// <remarks>
- /// <para>
- /// Gets all available caller information, in the format
- /// <c>fully.qualified.classname.of.caller.methodName(Filename:line)</c>
- /// </para>
- /// </remarks>
public string FullInfo { get; }
/// <summary>
/// Gets the stack frames from the stack trace of the caller making the log request
/// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays")]
public StackFrameItem[]? StackFrames { get; }
/// <summary>
@@ -249,7 +245,7 @@ public class LocationInfo : ILog4NetSerializable
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
// Use member names from log4net 2.x implicit serialization for cross-version compat.
- info.AddValue("m_className", ClassName);
+ info.EnsureNotNull().AddValue("m_className", ClassName);
info.AddValue("m_fileName", FileName);
info.AddValue("m_lineNumber", LineNumber);
info.AddValue("m_methodName", MethodName);
diff --git a/src/log4net/Core/LogException.cs b/src/log4net/Core/LogException.cs
index 21fa0235..f0da0c6e 100644
--- a/src/log4net/Core/LogException.cs
+++ b/src/log4net/Core/LogException.cs
@@ -35,6 +35,7 @@ namespace log4net.Core;
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
[Log4NetSerializable]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1058:Types should not extend certain base types")]
public class LogException : ApplicationException
{
/// <summary>
@@ -46,8 +47,7 @@ public class LogException : ApplicationException
/// </para>
/// </remarks>
public LogException()
- {
- }
+ { }
/// <summary>
/// Constructor
@@ -59,9 +59,9 @@ public class LogException : ApplicationException
/// the specified message.
/// </para>
/// </remarks>
- public LogException(string message) : base(message)
- {
- }
+ public LogException(string message)
+ : base(message)
+ { }
/// <summary>
/// Constructor
@@ -74,9 +74,9 @@ public class LogException : ApplicationException
/// with the specified message and inner exception.
/// </para>
/// </remarks>
- public LogException(string message, Exception innerException) : base(message, innerException)
- {
- }
+ public LogException(string message, Exception innerException)
+ : base(message, innerException)
+ { }
/// <summary>
/// Serialization constructor
@@ -91,6 +91,5 @@ public class LogException : ApplicationException
/// </remarks>
protected LogException(SerializationInfo info, StreamingContext context)
: base(info, context)
- {
- }
+ { }
}
\ No newline at end of file
diff --git a/src/log4net/Core/LogImpl.cs b/src/log4net/Core/LogImpl.cs
index 6c7a2912..aafc32d5 100644
--- a/src/log4net/Core/LogImpl.cs
+++ b/src/log4net/Core/LogImpl.cs
@@ -41,7 +41,7 @@ namespace log4net.Core;
/// <item>
/// <term>DEBUG</term>
/// <description>
-/// The <see cref="M:Debug(object)"/> and <see cref="M:DebugFormat(string, object[])"/> methods log messages
+/// The <see cref="Debug(object)"/> and <see cref="DebugFormat(string, object[])"/> methods log messages
/// at the <c>DEBUG</c> level. That is the level with that name defined in the
/// repositories <see cref="ILoggerRepository.LevelMap"/>. The default value
/// for this level is <see cref="Level.Debug"/>. The <see cref="IsDebugEnabled"/>
@@ -51,7 +51,7 @@ namespace log4net.Core;
/// <item>
/// <term>INFO</term>
/// <description>
-/// The <see cref="M:Info(object)"/> and <see cref="M:InfoFormat(string, object[])"/> methods log messages
+/// The <see cref="Info(object)"/> and <see cref="InfoFormat(string, object[])"/> methods log messages
/// at the <c>INFO</c> level. That is the level with that name defined in the
/// repositories <see cref="ILoggerRepository.LevelMap"/>. The default value
/// for this level is <see cref="Level.Info"/>. The <see cref="IsInfoEnabled"/>
@@ -61,7 +61,7 @@ namespace log4net.Core;
/// <item>
/// <term>WARN</term>
/// <description>
-/// The <see cref="M:Warn(object)"/> and <see cref="M:WarnFormat(string, object[])"/> methods log messages
+/// The <see cref="Warn(object)"/> and <see cref="WarnFormat(string, object[])"/> methods log messages
/// at the <c>WARN</c> level. That is the level with that name defined in the
/// repositories <see cref="ILoggerRepository.LevelMap"/>. The default value
/// for this level is <see cref="Level.Warn"/>. The <see cref="IsWarnEnabled"/>
@@ -71,7 +71,7 @@ namespace log4net.Core;
/// <item>
/// <term>ERROR</term>
/// <description>
-/// The <see cref="M:Error(object)"/> and <see cref="M:ErrorFormat(string, object[])"/> methods log messages
+/// The <see cref="Error(object)"/> and <see cref="ErrorFormat(string, object[])"/> methods log messages
/// at the <c>ERROR</c> level. That is the level with that name defined in the
/// repositories <see cref="ILoggerRepository.LevelMap"/>. The default value
/// for this level is <see cref="Level.Error"/>. The <see cref="IsErrorEnabled"/>
@@ -81,7 +81,7 @@ namespace log4net.Core;
/// <item>
/// <term>FATAL</term>
/// <description>
-/// The <see cref="M:Fatal(object)"/> and <see cref="M:FatalFormat(string, object[])"/> methods log messages
+/// The <see cref="Fatal(object)"/> and <see cref="FatalFormat(string, object[])"/> methods log messages
/// at the <c>FATAL</c> level. That is the level with that name defined in the
/// repositories <see cref="ILoggerRepository.LevelMap"/>. The default value
/// for this level is <see cref="Level.Fatal"/>. The <see cref="IsFatalEnabled"/>
@@ -96,6 +96,7 @@ namespace log4net.Core;
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public class LogImpl : LoggerWrapperImpl, ILog
{
/// <summary>
@@ -107,15 +108,17 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// Construct a new wrapper for the specified logger.
/// </para>
/// </remarks>
- public LogImpl(ILogger logger) : base(logger)
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public LogImpl(ILogger logger)
+ : base(logger)
{
- if (logger.Repository is not null)
+ if (logger.EnsureNotNull().Repository is ILoggerRepository repository)
{
// Listen for changes to the repository
- logger.Repository.ConfigurationChanged += LoggerRepositoryConfigurationChanged;
+ repository.ConfigurationChanged += LoggerRepositoryConfigurationChanged;
// load the current levels
- ReloadLevels(logger.Repository);
+ ReloadLevels(repository);
}
}
@@ -130,7 +133,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// </remarks>
protected virtual void ReloadLevels(ILoggerRepository repository)
{
- LevelMap levelMap = repository.LevelMap;
+ LevelMap levelMap = repository.EnsureNotNull().LevelMap;
_levelDebug = levelMap.LookupWithDefault(Level.Debug);
_levelInfo = levelMap.LookupWithDefault(Level.Info);
@@ -150,7 +153,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <c>DEBUG</c> level. If this logger is
/// <c>DEBUG</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
- /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
+ /// <see cref="ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of the
/// additivity flag.
@@ -159,13 +162,11 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Debug(object,Exception)"/> form instead.
+ /// <see cref="Debug(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- public virtual void Debug(object? message)
- {
- Logger.Log(_thisDeclaringType, _levelDebug, message, null);
- }
+ public virtual void Debug(object? message)
+ => Logger.Log(_thisDeclaringType, _levelDebug, message, null);
/// <summary>
/// Logs a message object with the <c>DEBUG</c> level
@@ -179,14 +180,12 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// as a parameter.
/// </para>
/// <para>
- /// See the <see cref="M:Debug(object)"/> form for more detailed information.
+ /// See the <see cref="Debug(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
- public virtual void Debug(object? message, Exception? exception)
- {
- Logger.Log(_thisDeclaringType, _levelDebug, message, exception);
- }
+ /// <seealso cref="Debug(object)"/>
+ public virtual void Debug(object? message, Exception? exception)
+ => Logger.Log(_thisDeclaringType, _levelDebug, message, exception);
/// <summary>
/// Logs a formatted message string with the <c>DEBUG</c> level.
@@ -195,18 +194,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -214,7 +213,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsDebugEnabled)
{
- Logger.Log(_thisDeclaringType, _levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelDebug,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
}
}
@@ -225,18 +225,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -244,7 +244,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsDebugEnabled)
{
- Logger.Log(_thisDeclaringType, _levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
+ Logger.Log(_thisDeclaringType, _levelDebug,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
}
}
@@ -256,18 +257,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg1">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -275,7 +276,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsDebugEnabled)
{
- Logger.Log(_thisDeclaringType, _levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
+ Logger.Log(_thisDeclaringType, _levelDebug,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
}
}
@@ -288,18 +290,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg2">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -307,7 +309,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsDebugEnabled)
{
- Logger.Log(_thisDeclaringType, _levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
+ Logger.Log(_thisDeclaringType, _levelDebug,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
}
}
@@ -319,13 +322,13 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -333,7 +336,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsDebugEnabled)
{
- Logger.Log(_thisDeclaringType, _levelDebug, new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelDebug,
+ new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
}
}
@@ -348,7 +352,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <c>INFO</c> level. If this logger is
/// <c>INFO</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
- /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
+ /// <see cref="ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of
/// the additivity flag.
@@ -357,13 +361,11 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Info(object,Exception)"/> form instead.
+ /// <see cref="Info(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- public virtual void Info(object? message)
- {
- Logger.Log(_thisDeclaringType, _levelInfo, message, null);
- }
+ public virtual void Info(object? message)
+ => Logger.Log(_thisDeclaringType, _levelInfo, message, null);
/// <summary>
/// Logs a message object with the <c>INFO</c> level.
@@ -377,14 +379,12 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// passed as a parameter.
/// </para>
/// <para>
- /// See the <see cref="M:Info(object)"/> form for more detailed information.
+ /// See the <see cref="Info(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
- public virtual void Info(object? message, Exception? exception)
- {
- Logger.Log(_thisDeclaringType, _levelInfo, message, exception);
- }
+ /// <seealso cref="Info(object)"/>
+ public virtual void Info(object? message, Exception? exception)
+ => Logger.Log(_thisDeclaringType, _levelInfo, message, exception);
/// <summary>
/// Logs a formatted message string with the <c>INFO</c> level.
@@ -393,18 +393,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -412,7 +412,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsInfoEnabled)
{
- Logger.Log(_thisDeclaringType, _levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelInfo,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
}
}
@@ -423,18 +424,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -442,7 +443,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsInfoEnabled)
{
- Logger.Log(_thisDeclaringType, _levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
+ Logger.Log(_thisDeclaringType, _levelInfo,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
}
}
@@ -454,18 +456,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg1">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -473,7 +475,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsInfoEnabled)
{
- Logger.Log(_thisDeclaringType, _levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
+ Logger.Log(_thisDeclaringType, _levelInfo,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
}
}
@@ -486,18 +489,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg2">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -505,7 +508,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsInfoEnabled)
{
- Logger.Log(_thisDeclaringType, _levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
+ Logger.Log(_thisDeclaringType, _levelInfo,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
}
}
@@ -517,13 +521,13 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -531,7 +535,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsInfoEnabled)
{
- Logger.Log(_thisDeclaringType, _levelInfo, new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelInfo,
+ new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
}
}
@@ -546,7 +551,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <c>WARN</c> level. If this logger is
/// <c>WARN</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
- /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
+ /// <see cref="ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger and
/// also higher in the hierarchy depending on the value of the
/// additivity flag.
@@ -555,13 +560,11 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <b>WARNING</b> Note that passing an <see cref="Exception"/> to this
/// method will print the name of the <see cref="Exception"/> but no
/// stack trace. To print a stack trace use the
- /// <see cref="M:Warn(object,Exception)"/> form instead.
+ /// <see cref="Warn(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- public virtual void Warn(object? message)
- {
- Logger.Log(_thisDeclaringType, _levelWarn, message, null);
- }
+ public virtual void Warn(object? message)
+ => Logger.Log(_thisDeclaringType, _levelWarn, message, null);
/// <summary>
/// Logs a message object with the <c>WARN</c> level
@@ -575,14 +578,12 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// passed as a parameter.
/// </para>
/// <para>
- /// See the <see cref="M:Warn(object)"/> form for more detailed information.
+ /// See the <see cref="Warn(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
- public virtual void Warn(object? message, Exception? exception)
- {
- Logger.Log(_thisDeclaringType, _levelWarn, message, exception);
- }
+ /// <seealso cref="Warn(object)"/>
+ public virtual void Warn(object? message, Exception? exception)
+ => Logger.Log(_thisDeclaringType, _levelWarn, message, exception);
/// <summary>
/// Logs a formatted message string with the <c>WARN</c> level.
@@ -591,18 +592,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -610,7 +611,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsWarnEnabled)
{
- Logger.Log(_thisDeclaringType, _levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelWarn,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
}
}
@@ -621,18 +623,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -640,7 +642,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsWarnEnabled)
{
- Logger.Log(_thisDeclaringType, _levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
+ Logger.Log(_thisDeclaringType, _levelWarn,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
}
}
@@ -652,18 +655,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg1">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -671,7 +674,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsWarnEnabled)
{
- Logger.Log(_thisDeclaringType, _levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
+ Logger.Log(_thisDeclaringType, _levelWarn,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
}
}
@@ -684,18 +688,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg2">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -703,7 +707,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsWarnEnabled)
{
- Logger.Log(_thisDeclaringType, _levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
+ Logger.Log(_thisDeclaringType, _levelWarn,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
}
}
@@ -715,13 +720,13 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -729,7 +734,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsWarnEnabled)
{
- Logger.Log(_thisDeclaringType, _levelWarn, new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelWarn,
+ new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
}
}
@@ -744,7 +750,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <c>ERROR</c> level. If this logger is
/// <c>ERROR</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
- /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
+ /// <see cref="ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger and
/// also higher in the hierarchy depending on the value of the
/// additivity flag.
@@ -753,13 +759,11 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <b>WARNING</b> Note that passing an <see cref="Exception"/> to this
/// method will print the name of the <see cref="Exception"/> but no
/// stack trace. To print a stack trace use the
- /// <see cref="M:Error(object,Exception)"/> form instead.
+ /// <see cref="Error(object,Exception)"/> form instead.
/// </para>
/// </remarks>
public virtual void Error(object? message)
- {
- Logger.Log(_thisDeclaringType, _levelError, message, null);
- }
+ => Logger.Log(_thisDeclaringType, _levelError, message, null);
/// <summary>
/// Logs a message object with the <c>ERROR</c> level
@@ -773,14 +777,12 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// passed as a parameter.
/// </para>
/// <para>
- /// See the <see cref="M:Error(object)"/> form for more detailed information.
+ /// See the <see cref="Error(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
- public virtual void Error(object? message, Exception? exception)
- {
- Logger.Log(_thisDeclaringType, _levelError, message, exception);
- }
+ /// <seealso cref="Error(object)"/>
+ public virtual void Error(object? message, Exception? exception)
+ => Logger.Log(_thisDeclaringType, _levelError, message, exception);
/// <summary>
/// Logs a formatted message string with the <c>ERROR</c> level.
@@ -789,18 +791,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -808,7 +810,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsErrorEnabled)
{
- Logger.Log(_thisDeclaringType, _levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelError,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
}
}
@@ -819,18 +822,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -838,7 +841,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsErrorEnabled)
{
- Logger.Log(_thisDeclaringType, _levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
+ Logger.Log(_thisDeclaringType, _levelError,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
}
}
@@ -850,18 +854,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg1">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -869,7 +873,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsErrorEnabled)
{
- Logger.Log(_thisDeclaringType, _levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
+ Logger.Log(_thisDeclaringType, _levelError,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
}
}
@@ -882,18 +887,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg2">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -901,7 +906,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsErrorEnabled)
{
- Logger.Log(_thisDeclaringType, _levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
+ Logger.Log(_thisDeclaringType, _levelError,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
}
}
@@ -913,13 +919,13 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -927,7 +933,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsErrorEnabled)
{
- Logger.Log(_thisDeclaringType, _levelError, new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelError,
+ new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
}
}
@@ -942,7 +949,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <c>FATAL</c> level. If this logger is
/// <c>FATAL</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
- /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
+ /// <see cref="ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger and
/// also higher in the hierarchy depending on the value of the
/// additivity flag.
@@ -951,13 +958,11 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <b>WARNING</b> Note that passing an <see cref="Exception"/> to this
/// method will print the name of the <see cref="Exception"/> but no
/// stack trace. To print a stack trace use the
- /// <see cref="M:Fatal(object,Exception)"/> form instead.
+ /// <see cref="Fatal(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- public virtual void Fatal(object? message)
- {
- Logger.Log(_thisDeclaringType, _levelFatal, message, null);
- }
+ public virtual void Fatal(object? message)
+ => Logger.Log(_thisDeclaringType, _levelFatal, message, null);
/// <summary>
/// Logs a message object with the <c>FATAL</c> level
@@ -971,14 +976,12 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// passed as a parameter.
/// </para>
/// <para>
- /// See the <see cref="M:Fatal(object)"/> form for more detailed information.
+ /// See the <see cref="Fatal(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
- public virtual void Fatal(object? message, Exception? exception)
- {
- Logger.Log(_thisDeclaringType, _levelFatal, message, exception);
- }
+ /// <seealso cref="Fatal(object)"/>
+ public virtual void Fatal(object? message, Exception? exception)
+ => Logger.Log(_thisDeclaringType, _levelFatal, message, exception);
/// <summary>
/// Logs a formatted message string with the <c>FATAL</c> level.
@@ -987,18 +990,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -1006,7 +1009,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsFatalEnabled)
{
- Logger.Log(_thisDeclaringType, _levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelFatal,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, args ?? _oneNullArgs), null);
}
}
@@ -1017,18 +1021,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -1036,7 +1040,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsFatalEnabled)
{
- Logger.Log(_thisDeclaringType, _levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
+ Logger.Log(_thisDeclaringType, _levelFatal,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0]), null);
}
}
@@ -1048,18 +1053,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg1">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -1067,7 +1072,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsFatalEnabled)
{
- Logger.Log(_thisDeclaringType, _levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
+ Logger.Log(_thisDeclaringType, _levelFatal,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1]), null);
}
}
@@ -1080,18 +1086,18 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="arg2">An Object to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
/// format provider. To specify a localized provider use the
- /// <see cref="M:FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -1099,7 +1105,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsFatalEnabled)
{
- Logger.Log(_thisDeclaringType, _levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
+ Logger.Log(_thisDeclaringType, _levelFatal,
+ new SystemStringFormat(CultureInfo.InvariantCulture, format, [arg0, arg1, arg2]), null);
}
}
@@ -1111,13 +1118,13 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
- /// The message is formatted using the <see cref="M:String.Format(IFormatProvider, string, object[])"/> method. See
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
/// <c>String.Format</c> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -1125,7 +1132,8 @@ public class LogImpl : LoggerWrapperImpl, ILog
{
if (IsFatalEnabled)
{
- Logger.Log(_thisDeclaringType, _levelFatal, new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
+ Logger.Log(_thisDeclaringType, _levelFatal,
+ new SystemStringFormat(provider, format, args ?? _oneNullArgs), null);
}
}
@@ -1187,7 +1195,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
/// of using this method.
/// </para>
/// </remarks>
- /// <seealso cref="LogImpl.IsDebugEnabled"/>
+ /// <seealso cref="IsDebugEnabled"/>
public virtual bool IsInfoEnabled => Logger.IsEnabledFor(_levelInfo);
/// <summary>
@@ -1237,7 +1245,7 @@ public class LogImpl : LoggerWrapperImpl, ILog
public virtual bool IsFatalEnabled => Logger.IsEnabledFor(_levelFatal);
/// <summary>
- /// Event handler for the <see cref="log4net.Repository.ILoggerRepository.ConfigurationChanged"/> event
+ /// Event handler for the <see cref="ILoggerRepository.ConfigurationChanged"/> event
/// </summary>
/// <param name="sender">the repository</param>
/// <param name="e">Empty</param>
diff --git a/src/log4net/Core/LoggerManager.cs b/src/log4net/Core/LoggerManager.cs
index f43b6e42..8b8084a7 100644
--- a/src/log4net/Core/LoggerManager.cs
+++ b/src/log4net/Core/LoggerManager.cs
@@ -278,7 +278,7 @@ public static class LoggerManager
=> RepositorySelector.GetRepository(repositoryAssembly.EnsureNotNull()).GetLogger(name.EnsureNotNull());
/// <summary>
- /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+ /// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <param name="repository">The repository to lookup in.</param>
/// <param name="type">The <paramref name="type"/> of which the fullname will be used as the name of the logger to retrieve.</param>
@@ -298,7 +298,7 @@ public static class LoggerManager
}
/// <summary>
- /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+ /// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <param name="repositoryAssembly">the assembly to use to look up the repository</param>
/// <param name="type">The <paramref name="type"/> of which the fullname will be used as the name of the logger to retrieve.</param>
@@ -476,7 +476,7 @@ public static class LoggerManager
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository(Assembly)"/> with the
+ /// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
@@ -509,7 +509,7 @@ public static class LoggerManager
/// <para>
/// The caller to <see cref="LogManager"/> supplies either a string name
/// or an assembly (if not supplied the assembly is inferred using
- /// <see cref="M:Assembly.GetCallingAssembly()"/>).
+ /// <see cref="Assembly.GetCallingAssembly()"/>).
/// </para>
/// <para>
/// This context is used by the selector to look up a specific repository.
@@ -544,7 +544,7 @@ public static class LoggerManager
/// Called when the <see cref="AppDomain.DomainUnload"/> event fires.
/// </para>
/// <para>
- /// When the event is triggered the log4net system is <see cref="M:Shutdown()"/>.
+ /// When the event is triggered the log4net system is <see cref="Shutdown()"/>.
/// </para>
/// </remarks>
private static void OnDomainUnload(object? sender, EventArgs e) => Shutdown();
@@ -559,7 +559,7 @@ public static class LoggerManager
/// Called when the <see cref="AppDomain.ProcessExit"/> event fires.
/// </para>
/// <para>
- /// When the event is triggered the log4net system is <see cref="M:Shutdown()"/>.
+ /// When the event is triggered the log4net system is <see cref="Shutdown()"/>.
/// </para>
/// </remarks>
private static void OnProcessExit(object? sender, EventArgs e) => Shutdown();
diff --git a/src/log4net/Core/LoggerWrapperImpl.cs b/src/log4net/Core/LoggerWrapperImpl.cs
index e4da0596..d502c33d 100644
--- a/src/log4net/Core/LoggerWrapperImpl.cs
+++ b/src/log4net/Core/LoggerWrapperImpl.cs
@@ -22,6 +22,7 @@ namespace log4net.Core;
/// <summary>
/// Implementation of the <see cref="ILoggerWrapper"/> interface.
/// </summary>
+/// <param name="logger">The logger to wrap.</param>
/// <remarks>
/// <para>
/// This class should be used as the base for all wrapper implementations.
@@ -29,22 +30,9 @@ namespace log4net.Core;
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
-public abstract class LoggerWrapperImpl : ILoggerWrapper
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
+public abstract class LoggerWrapperImpl(ILogger logger) : ILoggerWrapper
{
- /// <summary>
- /// Constructs a new wrapper for the specified logger.
- /// </summary>
- /// <param name="logger">The logger to wrap.</param>
- /// <remarks>
- /// <para>
- /// Constructs a new wrapper for the specified logger.
- /// </para>
- /// </remarks>
- protected LoggerWrapperImpl(ILogger logger)
- {
- Logger = logger;
- }
-
/// <summary>
/// Gets the implementation behind this wrapper object.
/// </summary>
@@ -61,5 +49,5 @@ public abstract class LoggerWrapperImpl : ILoggerWrapper
/// the log events.
/// </para>
/// </remarks>
- public virtual ILogger Logger { get; }
+ public virtual ILogger Logger { get; } = logger;
}
diff --git a/src/log4net/Core/LoggingEvent.cs b/src/log4net/Core/LoggingEvent.cs
index 4e0fca8a..5614414b 100644
--- a/src/log4net/Core/LoggingEvent.cs
+++ b/src/log4net/Core/LoggingEvent.cs
@@ -204,7 +204,7 @@ public class LoggingEvent : ILog4NetSerializable
Exception? exception)
{
_callerStackBoundaryDeclaringType = callerStackBoundaryDeclaringType;
- _message = message;
+ MessageObject = message;
Repository = repository;
ExceptionObject = exception;
@@ -233,7 +233,7 @@ public class LoggingEvent : ILog4NetSerializable
/// be useful if you require a custom serialization scheme.
/// </para>
/// <para>
- /// Use the <see cref="M:GetLoggingEventData(FixFlags)"/> method to obtain an
+ /// Use the <see cref="GetLoggingEventData(FixFlags)"/> method to obtain an
/// instance of the <see cref="LoggingEventData"/> class.
/// </para>
/// <para>
@@ -270,7 +270,7 @@ public class LoggingEvent : ILog4NetSerializable
/// be useful if you require a custom serialization scheme.
/// </para>
/// <para>
- /// Use the <see cref="M:GetLoggingEventData(FixFlags)"/> method to obtain an
+ /// Use the <see cref="GetLoggingEventData(FixFlags)"/> method to obtain an
/// instance of the <see cref="LoggingEventData"/> class.
/// </para>
/// <para>
@@ -298,7 +298,7 @@ public class LoggingEvent : ILog4NetSerializable
/// be useful if you require a custom serialization scheme.
/// </para>
/// <para>
- /// Use the <see cref="M:GetLoggingEventData(FixFlags)"/> method to obtain an
+ /// Use the <see cref="GetLoggingEventData(FixFlags)"/> method to obtain an
/// instance of the <see cref="LoggingEventData"/> class.
/// </para>
/// <para>
@@ -320,7 +320,7 @@ public class LoggingEvent : ILog4NetSerializable
/// or Newtonsoft.Json.
/// </para>
/// <para>
- /// Use the <see cref="M:GetLoggingEventData(FixFlags)"/> method to obtain an
+ /// Use the <see cref="GetLoggingEventData(FixFlags)"/> method to obtain an
/// instance of the <see cref="LoggingEventData"/> class.
/// </para>
/// <para>
@@ -341,6 +341,7 @@ public class LoggingEvent : ILog4NetSerializable
/// with serialized data.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter")]
protected LoggingEvent(SerializationInfo info, StreamingContext context)
{
_data = new()
@@ -505,11 +506,7 @@ public class LoggingEvent : ILog4NetSerializable
/// null will be returned.
/// </para>
/// </remarks>
- public object? MessageObject
- {
- get => _message;
- protected set => _message = value;
- }
+ public object? MessageObject { get; protected set; }
/// <summary>
/// Gets the exception object used to initialize this event.
@@ -572,22 +569,22 @@ public class LoggingEvent : ILog4NetSerializable
{
if (_data.Message is null && _cacheUpdatable)
{
- if (_message is null)
+ if (MessageObject is null)
{
_data.Message = string.Empty;
}
- else if (_message is string s)
+ else if (MessageObject is string s)
{
_data.Message = s;
}
else if (Repository is not null)
{
- _data.Message = Repository.RendererMap.FindAndRender(_message);
+ _data.Message = Repository.RendererMap.FindAndRender(MessageObject);
}
else
{
// Very last resort
- _data.Message = _message.ToString();
+ _data.Message = MessageObject.ToString();
}
}
@@ -617,20 +614,20 @@ public class LoggingEvent : ILog4NetSerializable
}
else
{
- if (_message is not null)
+ if (MessageObject is not null)
{
- if (_message is string s)
+ if (MessageObject is string s)
{
writer.Write(s);
}
else if (Repository is not null)
{
- Repository.RendererMap.FindAndRender(_message, writer);
+ Repository.RendererMap.FindAndRender(MessageObject, writer);
}
else
{
// Very last resort
- writer.Write(_message.ToString());
+ writer.Write(MessageObject.ToString());
}
}
}
@@ -973,10 +970,8 @@ public class LoggingEvent : ILog4NetSerializable
/// in the logging event before returning the event data.
/// </para>
/// </remarks>
- public LoggingEventData GetLoggingEventData()
- {
- return GetLoggingEventData(FixFlags.Partial);
- }
+ public LoggingEventData GetLoggingEventData()
+ => GetLoggingEventData(FixFlags.Partial);
/// <summary>
/// Gets the portable data for this <see cref="LoggingEvent" />.
@@ -1307,11 +1302,6 @@ public class LoggingEvent : ILog4NetSerializable
/// </summary>
private readonly Type? _callerStackBoundaryDeclaringType;
- /// <summary>
- /// The application supplied message of logging event.
- /// </summary>
- private object? _message;
-
/// <summary>
/// The fix state for this event
/// </summary>
diff --git a/src/log4net/Core/SecurityContextProvider.cs b/src/log4net/Core/SecurityContextProvider.cs
index abf44359..acd53903 100644
--- a/src/log4net/Core/SecurityContextProvider.cs
+++ b/src/log4net/Core/SecurityContextProvider.cs
@@ -58,7 +58,7 @@ public class SecurityContextProvider
/// <summary>
/// The default provider
/// </summary>
- private static SecurityContextProvider _sDefaultProvider = new SecurityContextProvider();
+ private static SecurityContextProvider _sDefaultProvider = new();
/// <summary>
/// Gets or sets the default SecurityContextProvider
diff --git a/src/log4net/Core/TimeEvaluator.cs b/src/log4net/Core/TimeEvaluator.cs
index f87b3567..e6672f4d 100644
--- a/src/log4net/Core/TimeEvaluator.cs
+++ b/src/log4net/Core/TimeEvaluator.cs
@@ -24,6 +24,10 @@ namespace log4net.Core;
/// <summary>
/// An evaluator that triggers after specified number of seconds.
/// </summary>
+/// <param name="interval">
+/// The time threshold in seconds to trigger after.
+/// Zero means it won't trigger at all.
+/// </param>
/// <remarks>
/// <para>
/// This evaluator will trigger if the specified time period
@@ -31,17 +35,14 @@ namespace log4net.Core;
/// </para>
/// </remarks>
/// <author>Robert Sevcik</author>
-public class TimeEvaluator : ITriggeringEventEvaluator
+public class TimeEvaluator(int interval) : ITriggeringEventEvaluator
{
- /// <summary>
- /// The time threshold for triggering in seconds. Zero means it won't trigger at all.
- /// </summary>
- private int _interval;
+ private readonly object _syncRoot = new();
/// <summary>
/// The UTC time of last check. This gets updated when the object is created and when the evaluator triggers.
/// </summary>
- private DateTime _lastTimeUtc;
+ private DateTime _lastTimeUtc = DateTime.UtcNow;
/// <summary>
/// The default time threshold for triggering in seconds. Zero means it won't trigger at all.
@@ -64,28 +65,6 @@ public class TimeEvaluator : ITriggeringEventEvaluator
: this(DefaultInterval)
{ }
- /// <summary>
- /// Create a new evaluator using the specified time threshold in seconds.
- /// </summary>
- /// <param name="interval">
- /// The time threshold in seconds to trigger after.
- /// Zero means it won't trigger at all.
- /// </param>
- /// <remarks>
- /// <para>
- /// Create a new evaluator using the specified time threshold in seconds.
- /// </para>
- /// <para>
- /// This evaluator will trigger if the specified time period
- /// <see cref="Interval"/> has passed since last check.
- /// </para>
- /// </remarks>
- public TimeEvaluator(int interval)
- {
- this._interval = interval;
- _lastTimeUtc = DateTime.UtcNow;
- }
-
/// <summary>
/// The time threshold in seconds to trigger after
/// </summary>
@@ -99,11 +78,7 @@ public class TimeEvaluator : ITriggeringEventEvaluator
/// <see cref="Interval"/> has passed since last check.
/// </para>
/// </remarks>
- public int Interval
- {
- get => _interval;
- set => _interval = value;
- }
+ public int Interval { get; set; } = interval;
/// <summary>
/// Is this <paramref name="loggingEvent"/> the triggering event?
@@ -120,22 +95,17 @@ public class TimeEvaluator : ITriggeringEventEvaluator
/// </remarks>
public bool IsTriggeringEvent(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
// disable the evaluator if threshold is zero
- if (_interval == 0)
+ if (Interval == 0)
{
return false;
}
- lock (this) // avoid triggering multiple times
+ lock (_syncRoot) // avoid triggering multiple times
{
TimeSpan passed = DateTime.UtcNow.Subtract(_lastTimeUtc);
- if (passed.TotalSeconds > _interval)
+ if (passed.TotalSeconds > Interval)
{
_lastTimeUtc = DateTime.UtcNow;
return true;
diff --git a/src/log4net/Core/WrapperMap.cs b/src/log4net/Core/WrapperMap.cs
index b7d260f8..f55e0fd3 100644
--- a/src/log4net/Core/WrapperMap.cs
+++ b/src/log4net/Core/WrapperMap.cs
@@ -21,6 +21,7 @@ using System;
using System.Collections;
using log4net.Repository;
+using log4net.Util;
namespace log4net.Core;
@@ -62,6 +63,7 @@ public delegate ILoggerWrapper WrapperCreationHandler(ILogger logger);
/// <author>Gert Driesen</author>
public class WrapperMap
{
+ private readonly object _syncRoot = new();
/// <summary>
/// Initializes a new instance of the <see cref="WrapperMap" />
/// </summary>
@@ -74,7 +76,7 @@ public class WrapperMap
/// </remarks>
public WrapperMap(WrapperCreationHandler createWrapperHandler)
{
- this._createWrapperHandler = createWrapperHandler;
+ _createWrapperHandler = createWrapperHandler;
// Create the delegates for the event callbacks
_shutdownHandler = ILoggerRepository_Shutdown;
@@ -103,7 +105,7 @@ public class WrapperMap
return null;
}
- lock (this)
+ lock (_syncRoot)
{
// Look up hierarchy in map.
Hashtable? wrappersMap = (Hashtable?)Repositories[logger.Repository];
@@ -164,10 +166,8 @@ public class WrapperMap
/// can be overridden in a subclass.
/// </para>
/// </remarks>
- protected virtual ILoggerWrapper CreateNewWrapperObject(ILogger logger)
- {
- return _createWrapperHandler.Invoke(logger);
- }
+ protected virtual ILoggerWrapper CreateNewWrapperObject(ILogger logger)
+ => _createWrapperHandler.Invoke(logger);
/// <summary>
/// Called when a monitored repository shutdown event is received.
@@ -184,10 +184,10 @@ public class WrapperMap
/// </remarks>
protected virtual void RepositoryShutdown(ILoggerRepository repository)
{
- lock (this)
+ lock (_syncRoot)
{
// Remove the repository from map
- Repositories.Remove(repository);
+ Repositories.Remove(repository.EnsureNotNull());
// Unhook events from the repository
repository.ShutdownEvent -= _shutdownHandler;
diff --git a/src/log4net/DateFormatter/AbsoluteTimeDateFormatter.cs b/src/log4net/DateFormatter/AbsoluteTimeDateFormatter.cs
index 4080f110..91b99d0d 100644
--- a/src/log4net/DateFormatter/AbsoluteTimeDateFormatter.cs
+++ b/src/log4net/DateFormatter/AbsoluteTimeDateFormatter.cs
@@ -17,6 +17,7 @@
//
#endregion
+using log4net.Util;
using System;
using System.Collections.Concurrent;
using System.IO;
@@ -51,6 +52,7 @@ public class AbsoluteTimeDateFormatter : IDateFormatter
/// </remarks>
protected virtual void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
+ buffer.EnsureNotNull();
int hour = dateToFormat.Hour;
if (hour < 10)
{
@@ -98,7 +100,7 @@ public class AbsoluteTimeDateFormatter : IDateFormatter
(_, existing) =>
{
// Calculate the current time precise only to the second
- long currentTimeToTheSecond = (dateToFormat.Ticks - (dateToFormat.Ticks % TimeSpan.TicksPerSecond));
+ long currentTimeToTheSecond = dateToFormat.Ticks - (dateToFormat.Ticks % TimeSpan.TicksPerSecond);
// Compare this time with the stored last time
// If we are in the same second then append
@@ -110,7 +112,7 @@ public class AbsoluteTimeDateFormatter : IDateFormatter
_sLastTimeToTheSecond = currentTimeToTheSecond;
return BuildTimeString();
});
- writer.Write(timeString);
+ writer.EnsureNotNull().Write(timeString);
// Append the current millisecond info
writer.Write(',');
diff --git a/src/log4net/DateFormatter/DateTimeDateFormatter.cs b/src/log4net/DateFormatter/DateTimeDateFormatter.cs
index 7750c487..2e0b2200 100644
--- a/src/log4net/DateFormatter/DateTimeDateFormatter.cs
+++ b/src/log4net/DateFormatter/DateTimeDateFormatter.cs
@@ -20,6 +20,7 @@
using System;
using System.Text;
using System.Globalization;
+using log4net.Util;
namespace log4net.DateFormatter;
@@ -55,6 +56,7 @@ public class DateTimeDateFormatter : AbsoluteTimeDateFormatter
/// </remarks>
protected override void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
+ buffer.EnsureNotNull();
int day = dateToFormat.Day;
if (day < 10)
{
diff --git a/src/log4net/DateFormatter/Iso8601DateFormatter.cs b/src/log4net/DateFormatter/Iso8601DateFormatter.cs
index 3a95d4b1..8cf7c9a5 100644
--- a/src/log4net/DateFormatter/Iso8601DateFormatter.cs
+++ b/src/log4net/DateFormatter/Iso8601DateFormatter.cs
@@ -17,6 +17,7 @@
//
#endregion
+using log4net.Util;
using System;
using System.Text;
@@ -50,7 +51,7 @@ public class Iso8601DateFormatter : AbsoluteTimeDateFormatter
/// </remarks>
protected override void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
- buffer.Append(dateToFormat.Year).Append('-');
+ buffer.EnsureNotNull().Append(dateToFormat.Year).Append('-');
int month = dateToFormat.Month;
if (month < 10)
diff --git a/src/log4net/DateFormatter/SimpleDateFormatter.cs b/src/log4net/DateFormatter/SimpleDateFormatter.cs
index 8a3966b9..f202863b 100644
--- a/src/log4net/DateFormatter/SimpleDateFormatter.cs
+++ b/src/log4net/DateFormatter/SimpleDateFormatter.cs
@@ -17,52 +17,36 @@
//
#endregion
+using log4net.Util;
using System;
using System.IO;
namespace log4net.DateFormatter;
/// <summary>
-/// Formats the <see cref="DateTime"/> using the <see cref="M:DateTime.ToString(string, IFormatProvider)"/> method.
+/// Formats the <see cref="DateTime"/> using the <see cref="DateTime.ToString(string, IFormatProvider)"/> method.
/// </summary>
/// <remarks>
/// <para>
-/// Formats the <see cref="DateTime"/> using the <see cref="DateTime"/> <see cref="M:DateTime.ToString(string, IFormatProvider)"/> method.
+/// Formats the <see cref="DateTime"/> using the <see cref="DateTime"/> <see cref="DateTime.ToString(string, IFormatProvider)"/> method.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
-public class SimpleDateFormatter : IDateFormatter
+/// <param name="format">The format string.</param>
+public class SimpleDateFormatter(string format) : IDateFormatter
{
/// <summary>
- /// Constructor
- /// </summary>
- /// <param name="format">The format string.</param>
- /// <remarks>
- /// <para>
- /// Initializes a new instance of the <see cref="SimpleDateFormatter" /> class
- /// with the specified format string.
- /// </para>
- /// <para>
- /// The format string must be compatible with the options
- /// that can be supplied to <see cref="M:DateTime.ToString(string, IFormatProvider)"/>.
- /// </para>
- /// </remarks>
- public SimpleDateFormatter(string format) => _formatString = format;
-
- /// <summary>
- /// Formats the date using <see cref="M:DateTime.ToString(string, IFormatProvider)"/>.
+ /// Formats the date using <see cref="DateTime.ToString(string, IFormatProvider)"/>.
/// </summary>
/// <param name="dateToFormat">The date to convert to a string.</param>
/// <param name="writer">The writer to write to.</param>
/// <remarks>
/// <para>
/// Uses the date format string supplied to the constructor to call
- /// the <see cref="M:DateTime.ToString(string, IFormatProvider)"/> method to format the date.
+ /// the <see cref="DateTime.ToString(string, IFormatProvider)"/> method to format the date.
/// </para>
/// </remarks>
public virtual void FormatDate(DateTime dateToFormat, TextWriter writer)
- => writer.Write(dateToFormat.ToString(_formatString, System.Globalization.DateTimeFormatInfo.InvariantInfo));
-
- private readonly string _formatString;
+ => writer.EnsureNotNull().Write(dateToFormat.ToString(format, System.Globalization.DateTimeFormatInfo.InvariantInfo));
}
\ No newline at end of file
diff --git a/src/log4net/Filter/LevelMatchFilter.cs b/src/log4net/Filter/LevelMatchFilter.cs
index 3fdef3e3..71769cdc 100644
--- a/src/log4net/Filter/LevelMatchFilter.cs
+++ b/src/log4net/Filter/LevelMatchFilter.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Filter;
@@ -87,11 +88,7 @@ public class LevelMatchFilter : FilterSkeleton
/// </remarks>
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
+ loggingEvent.EnsureNotNull();
if (LevelToMatch is not null && LevelToMatch == loggingEvent.Level)
{
// Found match
diff --git a/src/log4net/Filter/LevelRangeFilter.cs b/src/log4net/Filter/LevelRangeFilter.cs
index b90499e7..de6b9eb2 100644
--- a/src/log4net/Filter/LevelRangeFilter.cs
+++ b/src/log4net/Filter/LevelRangeFilter.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Filter;
@@ -98,39 +99,20 @@ public class LevelRangeFilter : FilterSkeleton
/// </remarks>
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
- if (LevelMin is not null)
+ if (LevelMin is not null && loggingEvent.Level is not null && loggingEvent.Level < LevelMin)
{
- if (loggingEvent.Level is not null && loggingEvent.Level < LevelMin)
- {
- // level of event is less than minimum
- return FilterDecision.Deny;
- }
+ // level of event is less than minimum
+ return FilterDecision.Deny;
}
- if (LevelMax is not null)
+ if (LevelMax is not null && loggingEvent.Level is not null && loggingEvent.Level > LevelMax)
{
- if (loggingEvent.Level is not null && loggingEvent.Level > LevelMax)
- {
- // level of event is greater than maximum
- return FilterDecision.Deny;
- }
+ // level of event is greater than maximum
+ return FilterDecision.Deny;
}
- if (AcceptOnMatch)
- {
- // this filter set up to bypass later filters and always return
- // accept if level in range
- return FilterDecision.Accept;
- }
- else
- {
- // event is ok for this filter; allow later filters to have a look..
- return FilterDecision.Neutral;
- }
+ return AcceptOnMatch ? FilterDecision.Accept : FilterDecision.Neutral;
}
}
diff --git a/src/log4net/Filter/LoggerMatchFilter.cs b/src/log4net/Filter/LoggerMatchFilter.cs
index 3d19bb5a..52e5c1a5 100644
--- a/src/log4net/Filter/LoggerMatchFilter.cs
+++ b/src/log4net/Filter/LoggerMatchFilter.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Filter;
@@ -63,7 +64,7 @@ public class LoggerMatchFilter : FilterSkeleton
/// <para>
/// This filter will attempt to match this value against logger name in
/// the following way. The match will be done against the beginning of the
- /// logger name (using <see cref="M:String.StartsWith(string)"/>). The match is
+ /// logger name (using <see cref="String.StartsWith(string)"/>). The match is
/// case sensitive. If a match is found then
/// the result depends on the value of <see cref="AcceptOnMatch"/>.
/// </para>
@@ -79,7 +80,7 @@ public class LoggerMatchFilter : FilterSkeleton
/// <para>
/// The rendered message is matched against the <see cref="LoggerToMatch"/>.
/// If the <see cref="LoggerToMatch"/> equals the beginning of
- /// the incoming <see cref="LoggingEvent.LoggerName"/> (<see cref="M:String.StartsWith(string)"/>)
+ /// the incoming <see cref="LoggingEvent.LoggerName"/> (<see cref="String.StartsWith(string)"/>)
/// then a match will have occurred. If no match occurs
/// this function will return <see cref="FilterDecision.Neutral"/>
/// allowing other filters to check the event. If a match occurs then
@@ -90,28 +91,17 @@ public class LoggerMatchFilter : FilterSkeleton
/// </remarks>
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
// Check if we have been set up to filter
- if (!string.IsNullOrEmpty(LoggerToMatch) &&
- loggingEvent.LoggerName is not null &&
- loggingEvent.LoggerName.StartsWith(LoggerToMatch))
+ if (!string.IsNullOrEmpty(LoggerToMatch)
+ && loggingEvent.LoggerName is not null
+ && loggingEvent.LoggerName.StartsWith(LoggerToMatch))
{
// we've got a match
- if (AcceptOnMatch)
- {
- return FilterDecision.Accept;
- }
- return FilterDecision.Deny;
- }
- else
- {
- // We cannot filter so allow the filter chain
- // to continue processing
- return FilterDecision.Neutral;
+ return AcceptOnMatch ? FilterDecision.Accept : FilterDecision.Deny;
}
+ // We cannot filter so allow the filter chain to continue processing
+ return FilterDecision.Neutral;
}
-}
+}
\ No newline at end of file
diff --git a/src/log4net/Filter/PropertyFilter.cs b/src/log4net/Filter/PropertyFilter.cs
index c1c6bfea..c872b503 100644
--- a/src/log4net/Filter/PropertyFilter.cs
+++ b/src/log4net/Filter/PropertyFilter.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Filter;
@@ -67,10 +68,7 @@ public class PropertyFilter : StringMatchFilter
/// </remarks>
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
// Check if we have a key to lookup the event property value with
if (Key is null)
@@ -106,11 +104,7 @@ public class PropertyFilter : StringMatchFilter
}
// we've got a match
- if (AcceptOnMatch)
- {
- return FilterDecision.Accept;
- }
- return FilterDecision.Deny;
+ return AcceptOnMatch ? FilterDecision.Accept : FilterDecision.Deny;
}
else if (StringToMatch is not null)
{
@@ -122,11 +116,7 @@ public class PropertyFilter : StringMatchFilter
}
// we've got a match
- if (AcceptOnMatch)
- {
- return FilterDecision.Accept;
- }
- return FilterDecision.Deny;
+ return AcceptOnMatch ? FilterDecision.Accept : FilterDecision.Deny;
}
return FilterDecision.Neutral;
}
diff --git a/src/log4net/Filter/StringMatchFilter.cs b/src/log4net/Filter/StringMatchFilter.cs
index b80df388..bbb12b3e 100644
--- a/src/log4net/Filter/StringMatchFilter.cs
+++ b/src/log4net/Filter/StringMatchFilter.cs
@@ -21,6 +21,7 @@ using System;
using System.Text.RegularExpressions;
using log4net.Core;
+using log4net.Util;
namespace log4net.Filter;
@@ -130,12 +131,7 @@ public class StringMatchFilter : FilterSkeleton
/// </remarks>
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
- string? msg = loggingEvent.RenderedMessage;
+ string? msg = loggingEvent.EnsureNotNull().RenderedMessage;
// Check if we have been setup to filter
if (msg is null || (StringToMatch is null && m_regexToMatch is null))
diff --git a/src/log4net/ILog.cs b/src/log4net/ILog.cs
index abeb5343..2e664676 100644
--- a/src/log4net/ILog.cs
+++ b/src/log4net/ILog.cs
@@ -18,6 +18,7 @@
#endregion
using System;
+using System.Reflection;
using log4net.Core;
@@ -30,7 +31,7 @@ namespace log4net;
/// <remarks>
/// <para>
/// Use the <see cref="LogManager"/> to obtain logger instances
-/// that implement this interface. The <see cref="M:LogManager.GetLogger(Assembly,Type)"/>
+/// that implement this interface. The <see cref="LogManager.GetLogger(Assembly,Type)"/>
/// static method is used to get logger instances.
/// </para>
/// <para>
@@ -59,7 +60,7 @@ namespace log4net;
/// </code>
/// </example>
/// <seealso cref="LogManager"/>
-/// <seealso cref="M:LogManager.GetLogger(Assembly, Type)"/>
+/// <seealso cref="LogManager.GetLogger(Assembly, Type)"/>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
public interface ILog : ILoggerWrapper
@@ -84,10 +85,10 @@ public interface ILog : ILoggerWrapper
/// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Debug(object,Exception)"/> form instead.
+ /// <see cref="Debug(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object,Exception)"/>
+ /// <seealso cref="Debug(object,Exception)"/>
/// <seealso cref="IsDebugEnabled"/>
void Debug(object? message);
@@ -100,10 +101,10 @@ public interface ILog : ILoggerWrapper
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// <para>
- /// See the <see cref="M:Debug(object)"/> form for more detailed information.
+ /// See the <see cref="Debug(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void Debug(object? message, Exception? exception);
@@ -116,16 +117,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void DebugFormat(string format, params object?[]? args);
@@ -137,16 +138,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void DebugFormat(string format, object? arg0);
@@ -159,16 +160,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void DebugFormat(string format, object? arg0, object? arg1);
@@ -182,16 +183,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void DebugFormat(string format, object? arg0, object? arg1, object? arg2);
@@ -204,16 +205,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Debug(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
+ /// <seealso cref="Debug(object)"/>
/// <seealso cref="IsDebugEnabled"/>
void DebugFormat(IFormatProvider? provider, string format, params object?[]? args);
@@ -236,11 +237,11 @@ public interface ILog : ILoggerWrapper
/// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Info(object,Exception)"/> form instead.
+ /// <see cref="Info(object,Exception)"/> form instead.
/// </para>
/// </remarks>
/// <param name="message">The message object to log.</param>
- /// <seealso cref="M:Info(object,Exception)"/>
+ /// <seealso cref="Info(object,Exception)"/>
/// <seealso cref="IsInfoEnabled"/>
void Info(object? message);
@@ -253,10 +254,10 @@ public interface ILog : ILoggerWrapper
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// <para>
- /// See the <see cref="M:Info(object)"/> form for more detailed information.
+ /// See the <see cref="Info(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
+ /// <seealso cref="Info(object)"/>
/// <seealso cref="IsInfoEnabled"/>
void Info(object? message, Exception? exception);
@@ -269,16 +270,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object,Exception)"/>
+ /// <seealso cref="Info(object,Exception)"/>
/// <seealso cref="IsInfoEnabled"/>
void InfoFormat(string format, params object?[]? args);
@@ -290,16 +291,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
+ /// <seealso cref="Info(object)"/>
/// <seealso cref="IsInfoEnabled"/>
void InfoFormat(string format, object? arg0);
@@ -312,16 +313,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
+ /// <seealso cref="Info(object)"/>
/// <seealso cref="IsInfoEnabled"/>
void InfoFormat(string format, object? arg0, object? arg1);
@@ -335,16 +336,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
+ /// <seealso cref="Info(object)"/>
/// <seealso cref="IsInfoEnabled"/>
void InfoFormat(string format, object? arg0, object? arg1, object? arg2);
@@ -357,16 +358,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Info(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Info(object,Exception)"/>
+ /// <seealso cref="Info(object,Exception)"/>
/// <seealso cref="IsInfoEnabled"/>
void InfoFormat(IFormatProvider? provider, string format, params object?[]? args);
@@ -389,11 +390,11 @@ public interface ILog : ILoggerWrapper
/// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Warn(object,Exception)"/> form instead.
+ /// <see cref="Warn(object,Exception)"/> form instead.
/// </para>
/// </remarks>
/// <param name="message">The message object to log.</param>
- /// <seealso cref="M:Warn(object,Exception)"/>
+ /// <seealso cref="Warn(object,Exception)"/>
/// <seealso cref="IsWarnEnabled"/>
void Warn(object? message);
@@ -406,10 +407,10 @@ public interface ILog : ILoggerWrapper
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// <para>
- /// See the <see cref="M:Warn(object)"/> form for more detailed information.
+ /// See the <see cref="Warn(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
+ /// <seealso cref="Warn(object)"/>
/// <seealso cref="IsWarnEnabled"/>
void Warn(object? message, Exception? exception);
@@ -422,16 +423,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object,Exception)"/>
+ /// <seealso cref="Warn(object,Exception)"/>
/// <seealso cref="IsWarnEnabled"/>
void WarnFormat(string format, params object?[]? args);
@@ -443,16 +444,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
+ /// <seealso cref="Warn(object)"/>
/// <seealso cref="IsWarnEnabled"/>
void WarnFormat(string format, object? arg0);
@@ -465,16 +466,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
+ /// <seealso cref="Warn(object)"/>
/// <seealso cref="IsWarnEnabled"/>
void WarnFormat(string format, object? arg0, object? arg1);
@@ -488,16 +489,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
+ /// <seealso cref="Warn(object)"/>
/// <seealso cref="IsWarnEnabled"/>
void WarnFormat(string format, object? arg0, object? arg1, object? arg2);
@@ -510,16 +511,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Warn(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Warn(object,Exception)"/>
+ /// <seealso cref="Warn(object,Exception)"/>
/// <seealso cref="IsWarnEnabled"/>
void WarnFormat(IFormatProvider? provider, string format, params object?[]? args);
@@ -543,10 +544,10 @@ public interface ILog : ILoggerWrapper
/// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Error(object,Exception)"/> form instead.
+ /// <see cref="Error(object,Exception)"/> form instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object,Exception)"/>
+ /// <seealso cref="Error(object,Exception)"/>
/// <seealso cref="IsErrorEnabled"/>
void Error(object? message);
@@ -559,10 +560,10 @@ public interface ILog : ILoggerWrapper
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// <para>
- /// See the <see cref="M:Error(object)"/> form for more detailed information.
+ /// See the <see cref="Error(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
+ /// <seealso cref="Error(object)"/>
/// <seealso cref="IsErrorEnabled"/>
void Error(object? message, Exception? exception);
@@ -575,16 +576,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object,Exception)"/>
+ /// <seealso cref="Error(object,Exception)"/>
/// <seealso cref="IsErrorEnabled"/>
void ErrorFormat(string format, params object?[]? args);
@@ -596,16 +597,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
+ /// <seealso cref="Error(object)"/>
/// <seealso cref="IsErrorEnabled"/>
void ErrorFormat(string format, object? arg0);
@@ -618,16 +619,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
+ /// <seealso cref="Error(object)"/>
/// <seealso cref="IsErrorEnabled"/>
void ErrorFormat(string format, object? arg0, object? arg1);
@@ -641,16 +642,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
+ /// <seealso cref="Error(object)"/>
/// <seealso cref="IsErrorEnabled"/>
void ErrorFormat(string format, object? arg0, object? arg1, object? arg2);
@@ -663,16 +664,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Error(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Error(object,Exception)"/>
+ /// <seealso cref="Error(object,Exception)"/>
/// <seealso cref="IsErrorEnabled"/>
void ErrorFormat(IFormatProvider? provider, string format, params object?[]? args);
@@ -695,11 +696,11 @@ public interface ILog : ILoggerWrapper
/// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
/// to this method will print the name of the <see cref="Exception"/>
/// but no stack trace. To print a stack trace use the
- /// <see cref="M:Fatal(object,Exception)"/> form instead.
+ /// <see cref="Fatal(object,Exception)"/> form instead.
/// </para>
/// </remarks>
/// <param name="message">The message object to log.</param>
- /// <seealso cref="M:Fatal(object,Exception)"/>
+ /// <seealso cref="Fatal(object,Exception)"/>
/// <seealso cref="IsFatalEnabled"/>
void Fatal(object? message);
@@ -712,10 +713,10 @@ public interface ILog : ILoggerWrapper
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// <para>
- /// See the <see cref="M:Fatal(object)"/> form for more detailed information.
+ /// See the <see cref="Fatal(object)"/> form for more detailed information.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
+ /// <seealso cref="Fatal(object)"/>
/// <seealso cref="IsFatalEnabled"/>
void Fatal(object? message, Exception? exception);
@@ -728,16 +729,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object,Exception)"/>
+ /// <seealso cref="Fatal(object,Exception)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(string format, params object?[]? args);
@@ -749,16 +750,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
+ /// <seealso cref="Fatal(object)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(string format, object? arg0);
@@ -771,16 +772,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
+ /// <seealso cref="Fatal(object)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(string format, object? arg0, object? arg1);
@@ -794,16 +795,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object,Exception)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
+ /// <seealso cref="Fatal(object)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(string format, object? arg0, object? arg1, object? arg2);
@@ -816,16 +817,16 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
- /// <see cref="M:String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="M:Fatal(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
/// methods instead.
/// </para>
/// </remarks>
- /// <seealso cref="M:Fatal(object,Exception)"/>
+ /// <seealso cref="Fatal(object,Exception)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(IFormatProvider? provider, string format, params object?[]? args);
@@ -863,7 +864,7 @@ public interface ILog : ILoggerWrapper
/// the other hand, if the <c>log</c> is debug enabled, you
/// will incur the cost of evaluating whether the logger is debug
/// enabled twice. Once in <see cref="IsDebugEnabled"/> and once in
- /// the <see cref="M:Debug(object)"/>. This is an insignificant overhead
+ /// the <see cref="Debug(object)"/>. This is an insignificant overhead
/// since evaluating a logger takes about 1% of the time it
/// takes to actually log. This is the preferred style of logging.
/// </para>
@@ -896,8 +897,8 @@ public interface ILog : ILoggerWrapper
/// speed or runtime flexibility.
/// </para>
/// </remarks>
- /// <seealso cref="M:Debug(object)"/>
- /// <seealso cref="M:DebugFormat(IFormatProvider, string, object[])"/>
+ /// <seealso cref="Debug(object)"/>
+ /// <seealso cref="DebugFormat(IFormatProvider, string, object[])"/>
bool IsDebugEnabled { get; }
/// <summary>
@@ -909,8 +910,8 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// For more information see <see cref="ILog.IsDebugEnabled"/>.
/// </remarks>
- /// <seealso cref="M:Info(object)"/>
- /// <seealso cref="M:InfoFormat(IFormatProvider, string, object[])"/>
+ /// <seealso cref="Info(object)"/>
+ /// <seealso cref="InfoFormat(IFormatProvider, string, object[])"/>
/// <seealso cref="ILog.IsDebugEnabled"/>
bool IsInfoEnabled { get; }
@@ -923,8 +924,8 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// For more information see <see cref="ILog.IsDebugEnabled"/>.
/// </remarks>
- /// <seealso cref="M:Warn(object)"/>
- /// <seealso cref="M:WarnFormat(IFormatProvider, string, object[])"/>
+ /// <seealso cref="Warn(object)"/>
+ /// <seealso cref="WarnFormat(IFormatProvider, string, object[])"/>
/// <seealso cref="ILog.IsDebugEnabled"/>
bool IsWarnEnabled { get; }
@@ -937,8 +938,8 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// For more information see <see cref="ILog.IsDebugEnabled"/>.
/// </remarks>
- /// <seealso cref="M:Error(object)"/>
- /// <seealso cref="M:ErrorFormat(IFormatProvider, string, object[])"/>
+ /// <seealso cref="Error(object)"/>
+ /// <seealso cref="ErrorFormat(IFormatProvider, string, object[])"/>
/// <seealso cref="ILog.IsDebugEnabled"/>
bool IsErrorEnabled { get; }
@@ -951,8 +952,8 @@ public interface ILog : ILoggerWrapper
/// <remarks>
/// For more information see <see cref="ILog.IsDebugEnabled"/>.
/// </remarks>
- /// <seealso cref="M:Fatal(object)"/>
- /// <seealso cref="M:FatalFormat(IFormatProvider, string, object[])"/>
+ /// <seealso cref="Fatal(object)"/>
+ /// <seealso cref="FatalFormat(IFormatProvider, string, object[])"/>
/// <seealso cref="ILog.IsDebugEnabled"/>
bool IsFatalEnabled { get; }
}
diff --git a/src/log4net/Layout/ExceptionLayout.cs b/src/log4net/Layout/ExceptionLayout.cs
index 77675ed7..ea6bab94 100644
--- a/src/log4net/Layout/ExceptionLayout.cs
+++ b/src/log4net/Layout/ExceptionLayout.cs
@@ -21,6 +21,7 @@ using System;
using System.IO;
using log4net.Core;
+using log4net.Util;
namespace log4net.Layout;
@@ -40,10 +41,7 @@ public class ExceptionLayout : LayoutSkeleton
/// <summary>
/// Constructs an ExceptionLayout.
/// </summary>
- public ExceptionLayout()
- {
- IgnoresException = false;
- }
+ public ExceptionLayout() => IgnoresException = false;
/// <summary>
/// Activates component options.
@@ -70,16 +68,9 @@ public class ExceptionLayout : LayoutSkeleton
/// <remarks>
/// <para>
/// Write the exception string to the <see cref="TextWriter"/>.
- /// The exception string is retrieved from <see cref="M:LoggingEvent.GetExceptionString()"/>.
+ /// The exception string is retrieved from <see cref="LoggingEvent.GetExceptionString()"/>.
/// </para>
/// </remarks>
- public override void Format(TextWriter writer, LoggingEvent loggingEvent)
- {
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
-
- writer.Write(loggingEvent.GetExceptionString());
- }
+ public override void Format(TextWriter writer, LoggingEvent loggingEvent)
+ => writer.EnsureNotNull().Write(loggingEvent.EnsureNotNull().GetExceptionString());
}
diff --git a/src/log4net/Layout/ILayout.cs b/src/log4net/Layout/ILayout.cs
index f98d1bef..381f28b0 100644
--- a/src/log4net/Layout/ILayout.cs
+++ b/src/log4net/Layout/ILayout.cs
@@ -29,7 +29,7 @@ namespace log4net.Layout;
/// <remarks>
/// <para>
/// An <see cref="ILayout"/> object is used to format a <see cref="LoggingEvent"/>
-/// as text. The <see cref="M:Format(TextWriter,LoggingEvent)"/> method is called by an
+/// as text. The <see cref="Format(TextWriter,LoggingEvent)"/> method is called by an
/// appender to transform the <see cref="LoggingEvent"/> into a string.
/// </para>
/// <para>
diff --git a/src/log4net/Layout/LayoutSkeleton.cs b/src/log4net/Layout/LayoutSkeleton.cs
index 4b890046..d026a173 100644
--- a/src/log4net/Layout/LayoutSkeleton.cs
+++ b/src/log4net/Layout/LayoutSkeleton.cs
@@ -35,7 +35,7 @@ namespace log4net.Layout;
/// <remarks>
/// <note type="inheritinfo">
/// <para>
-/// Subclasses must implement the <see cref="M:Format(TextWriter,LoggingEvent)"/>
+/// Subclasses must implement the <see cref="Format(TextWriter,LoggingEvent)"/>
/// method.
/// </para>
/// <para>
diff --git a/src/log4net/Layout/Pattern/DatePatternConverter.cs b/src/log4net/Layout/Pattern/DatePatternConverter.cs
index 1158bee0..f7bd0786 100644
--- a/src/log4net/Layout/Pattern/DatePatternConverter.cs
+++ b/src/log4net/Layout/Pattern/DatePatternConverter.cs
@@ -68,7 +68,7 @@ namespace log4net.Layout.Pattern;
/// <description>
/// Any other pattern string uses the <see cref="SimpleDateFormatter"/> formatter.
/// This formatter passes the pattern string to the <see cref="DateTime"/>
-/// <see cref="M:DateTime.ToString(string)"/> method.
+/// <see cref="DateTime.ToString(string)"/> method.
/// For details on valid patterns see
/// <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp">DateTimeFormatInfo Class</a>.
/// </description>
diff --git a/src/log4net/Layout/Pattern/NamedPatternConverter.cs b/src/log4net/Layout/Pattern/NamedPatternConverter.cs
index af020643..4671a492 100644
--- a/src/log4net/Layout/Pattern/NamedPatternConverter.cs
+++ b/src/log4net/Layout/Pattern/NamedPatternConverter.cs
@@ -112,6 +112,7 @@ public abstract class NamedPatternConverter : PatternLayoutConverter, IOptionHan
/// </remarks>
protected sealed override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
+ writer.EnsureNotNull();
string? name = GetFullyQualifiedName(loggingEvent);
if (_precision <= 0 || name is null || name.Length < 2)
{
diff --git a/src/log4net/Layout/Pattern/PatternLayoutConverter.cs b/src/log4net/Layout/Pattern/PatternLayoutConverter.cs
index f31ce0fd..9e4163f7 100644
--- a/src/log4net/Layout/Pattern/PatternLayoutConverter.cs
+++ b/src/log4net/Layout/Pattern/PatternLayoutConverter.cs
@@ -80,7 +80,7 @@ public abstract class PatternLayoutConverter : PatternConverter
{
if (state is not LoggingEvent loggingEvent)
{
- throw new ArgumentException($"state must be of type [{typeof(LoggingEvent).FullName}]", "state");
+ throw new ArgumentException($"state must be of type [{typeof(LoggingEvent).FullName}]", nameof(state));
}
Convert(writer, loggingEvent);
diff --git a/src/log4net/Layout/PatternLayout.cs b/src/log4net/Layout/PatternLayout.cs
index 069cc951..63859958 100644
--- a/src/log4net/Layout/PatternLayout.cs
+++ b/src/log4net/Layout/PatternLayout.cs
@@ -39,7 +39,7 @@ namespace log4net.Layout;
/// </summary>
/// <remarks>
/// <para>
-/// The goal of this class is to <see cref="M:PatternLayout.Format(TextWriter,LoggingEvent)"/> a
+/// The goal of this class is to <see cref="PatternLayout.Format(TextWriter,LoggingEvent)"/> a
/// <see cref="LoggingEvent"/> as a string. The results
/// depend on the <i>conversion pattern</i>.
/// </para>
@@ -178,7 +178,7 @@ namespace log4net.Layout;
/// </para>
/// <para>
/// The date format specifier admits the same syntax as the
-/// time pattern string of the <see cref="M:DateTime.ToString(string)"/>.
+/// time pattern string of the <see cref="DateTime.ToString(string)"/>.
/// </para>
/// <para>
/// For better results it is recommended to use the log4net date
@@ -191,7 +191,7 @@ namespace log4net.Layout;
/// </para>
/// <para>
/// These dedicated date formatters perform significantly
-/// better than <see cref="M:DateTime.ToString(string)"/>.
+/// better than <see cref="DateTime.ToString(string)"/>.
/// </para>
/// </description>
/// </item>
@@ -575,7 +575,7 @@ namespace log4net.Layout;
/// </para>
/// <para>
/// The date format specifier admits the same syntax as the
-/// time pattern string of the <see cref="M:DateTime.ToString(string)"/>.
+/// time pattern string of the <see cref="DateTime.ToString(string)"/>.
/// </para>
/// <para>
/// For better results it is recommended to use the log4net date
@@ -588,7 +588,7 @@ namespace log4net.Layout;
/// </para>
/// <para>
/// These dedicated date formatters perform significantly
-/// better than <see cref="M:DateTime.ToString(string)"/>.
+/// better than <see cref="DateTime.ToString(string)"/>.
/// </para>
/// </description>
/// </item>
@@ -760,7 +760,7 @@ namespace log4net.Layout;
/// </note>
/// <para>
/// Additional pattern converters may be registered with a specific <see cref="PatternLayout"/>
-/// instance using the <see cref="M:AddConverter(string, Type)"/> method.
+/// instance using the <see cref="AddConverter(string, Type)"/> method.
/// </para>
/// </remarks>
/// <example>
@@ -1062,7 +1062,7 @@ public class PatternLayout : LayoutSkeleton
/// <remarks>
/// <para>
/// This version of the method is used by the configurator.
- /// Programmatic users should use the alternative <see cref="M:AddConverter(string,Type)"/> method.
+ /// Programmatic users should use the alternative <see cref="AddConverter(string,Type)"/> method.
/// </para>
/// </remarks>
public void AddConverter(ConverterInfo converterInfo)
diff --git a/src/log4net/Layout/RawLayoutConverter.cs b/src/log4net/Layout/RawLayoutConverter.cs
index 78057aad..84e66624 100644
--- a/src/log4net/Layout/RawLayoutConverter.cs
+++ b/src/log4net/Layout/RawLayoutConverter.cs
@@ -51,7 +51,7 @@ public class RawLayoutConverter : IConvertFrom
public bool CanConvertFrom(Type sourceType)
{
// Accept an ILayout object
- return (typeof(ILayout).IsAssignableFrom(sourceType));
+ return typeof(ILayout).IsAssignableFrom(sourceType);
}
/// <summary>
diff --git a/src/log4net/Layout/RawPropertyLayout.cs b/src/log4net/Layout/RawPropertyLayout.cs
index c9db0276..0a5f914c 100644
--- a/src/log4net/Layout/RawPropertyLayout.cs
+++ b/src/log4net/Layout/RawPropertyLayout.cs
@@ -18,6 +18,7 @@
#endregion
using log4net.Core;
+using log4net.Util;
namespace log4net.Layout;
@@ -44,8 +45,6 @@ public class RawPropertyLayout : IRawLayout
/// with than name then <c>null</c> will be returned.
/// </para>
/// </remarks>
- public virtual object? Format(LoggingEvent loggingEvent)
- {
- return loggingEvent.LookupProperty(Key);
- }
+ public virtual object? Format(LoggingEvent loggingEvent)
+ => loggingEvent.EnsureNotNull().LookupProperty(Key);
}
diff --git a/src/log4net/Layout/RawTimeStampLayout.cs b/src/log4net/Layout/RawTimeStampLayout.cs
index c87c8ac0..1cb8e5f9 100644
--- a/src/log4net/Layout/RawTimeStampLayout.cs
+++ b/src/log4net/Layout/RawTimeStampLayout.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Layout;
@@ -41,8 +42,6 @@ public class RawTimeStampLayout : IRawLayout
/// in universal time use <see cref="RawUtcTimeStampLayout"/>.
/// </para>
/// </remarks>
- public virtual object Format(LoggingEvent loggingEvent)
- {
- return loggingEvent.TimeStamp;
- }
-}
+ public virtual object Format(LoggingEvent loggingEvent)
+ => loggingEvent.EnsureNotNull().TimeStamp;
+}
\ No newline at end of file
diff --git a/src/log4net/Layout/RawUtcTimeStampLayout.cs b/src/log4net/Layout/RawUtcTimeStampLayout.cs
index d52d5a76..e292e1b5 100644
--- a/src/log4net/Layout/RawUtcTimeStampLayout.cs
+++ b/src/log4net/Layout/RawUtcTimeStampLayout.cs
@@ -20,6 +20,7 @@
using System;
using log4net.Core;
+using log4net.Util;
namespace log4net.Layout;
@@ -41,8 +42,6 @@ public class RawUtcTimeStampLayout : IRawLayout
/// in local time use <see cref="RawTimeStampLayout"/>.
/// </para>
/// </remarks>
- public virtual object Format(LoggingEvent loggingEvent)
- {
- return loggingEvent.TimeStampUtc;
- }
+ public virtual object Format(LoggingEvent loggingEvent)
+ => loggingEvent.EnsureNotNull().TimeStampUtc;
}
diff --git a/src/log4net/Layout/SimpleLayout.cs b/src/log4net/Layout/SimpleLayout.cs
index e04aa456..c25e3a9c 100644
--- a/src/log4net/Layout/SimpleLayout.cs
+++ b/src/log4net/Layout/SimpleLayout.cs
@@ -21,6 +21,7 @@ using System;
using System.IO;
using log4net.Core;
+using log4net.Util;
namespace log4net.Layout;
@@ -43,10 +44,7 @@ public class SimpleLayout : LayoutSkeleton
/// <summary>
/// Constructs a SimpleLayout
/// </summary>
- public SimpleLayout()
- {
- IgnoresException = true;
- }
+ public SimpleLayout() => IgnoresException = true;
/// <summary>
/// Initialize layout options
@@ -83,14 +81,11 @@ public class SimpleLayout : LayoutSkeleton
/// </remarks>
public override void Format(TextWriter writer, LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ writer.EnsureNotNull();
- if (loggingEvent.Level is not null)
+ if (loggingEvent.EnsureNotNull().Level is Level level)
{
- writer.Write(loggingEvent.Level.DisplayName);
+ writer.Write(level.DisplayName);
writer.Write(" - ");
}
loggingEvent.WriteRenderedMessage(writer);
diff --git a/src/log4net/Layout/XmlLayout.cs b/src/log4net/Layout/XmlLayout.cs
index 5925fda3..0233808c 100644
--- a/src/log4net/Layout/XmlLayout.cs
+++ b/src/log4net/Layout/XmlLayout.cs
@@ -191,8 +191,8 @@ public class XmlLayout : XmlLayoutBase
/// </remarks>
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
- writer.WriteStartElement(_eventElementName, Prefix, DefaultEventElementName, Prefix);
- writer.WriteAttributeString(LoggerAttributeName, loggingEvent.LoggerName!);
+ writer.EnsureNotNull().WriteStartElement(_eventElementName, Prefix, DefaultEventElementName, Prefix);
+ writer.WriteAttributeString(LoggerAttributeName, loggingEvent.EnsureNotNull().LoggerName!);
writer.WriteAttributeString(TimestampAttributeName, XmlConvert.ToString(loggingEvent.TimeStamp, XmlDateTimeSerializationMode.Local));
diff --git a/src/log4net/Layout/XmlLayoutBase.cs b/src/log4net/Layout/XmlLayoutBase.cs
index 89890e56..705ec671 100644
--- a/src/log4net/Layout/XmlLayoutBase.cs
+++ b/src/log4net/Layout/XmlLayoutBase.cs
@@ -52,10 +52,7 @@ public abstract class XmlLayoutBase : LayoutSkeleton
/// with no location info.
/// </para>
/// </remarks>
- protected XmlLayoutBase() : this(false)
- {
- IgnoresException = false;
- }
+ protected XmlLayoutBase() : this(false) => IgnoresException = false;
/// <summary>
/// Protected constructor to support subclasses
@@ -169,10 +166,8 @@ public abstract class XmlLayoutBase : LayoutSkeleton
/// </remarks>
public override void Format(TextWriter writer, LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
+
using XmlWriter xmlWriter = XmlWriterExtensions.CreateXmlWriter(writer);
// Write the event to the writer
FormatXml(xmlWriter, loggingEvent);
@@ -191,8 +186,7 @@ public abstract class XmlLayoutBase : LayoutSkeleton
/// <param name="loggingEvent">The event to write.</param>
/// <remarks>
/// <para>
- /// Subclasses should override this method to format
- /// the <see cref="LoggingEvent"/> as XML.
+ /// Subclasses should override this method to format the <see cref="LoggingEvent"/> as XML.
/// </para>
/// </remarks>
protected abstract void FormatXml(XmlWriter writer, LoggingEvent loggingEvent);
diff --git a/src/log4net/Layout/XmlLayoutSchemaLog4j.cs b/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
index 9bf6c111..4d770f79 100644
--- a/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
+++ b/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
@@ -81,9 +81,10 @@ public class XmlLayoutSchemaLog4J : XmlLayoutBase
/// </remarks>
public string Version
{
- get { return "1.2"; }
+ get => "1.2";
set
{
+ _ = this;
if (value != "1.2")
{
throw new ArgumentException("Only version 1.2 of the log4j schema is currently supported");
@@ -129,23 +130,21 @@ method="run" file="Generator.java" line="94"/>
// Translate logging events for log4j
// Translate hostname property
- if (loggingEvent.LookupProperty(LoggingEvent.HostNameProperty) is not null &&
- loggingEvent.LookupProperty("log4jmachinename") is null)
+ if (loggingEvent.EnsureNotNull().LookupProperty(LoggingEvent.HostNameProperty) is not null
+ && loggingEvent.LookupProperty("log4jmachinename") is null)
{
loggingEvent.GetProperties()["log4jmachinename"] = loggingEvent.LookupProperty(LoggingEvent.HostNameProperty);
}
// translate appdomain name
- if (loggingEvent.LookupProperty("log4japp") is null &&
- loggingEvent.Domain is not null &&
- loggingEvent.Domain.Length > 0)
+ if (loggingEvent.LookupProperty("log4japp") is null
+ && loggingEvent.Domain?.Length > 0)
{
loggingEvent.GetProperties()["log4japp"] = loggingEvent.Domain;
}
// translate identity name
- if (loggingEvent.Identity is not null &&
- loggingEvent.Identity.Length > 0 &&
+ if (loggingEvent.Identity?.Length > 0 &&
loggingEvent.LookupProperty(LoggingEvent.IdentityProperty) is null)
{
loggingEvent.GetProperties()[LoggingEvent.IdentityProperty] = loggingEvent.Identity;
@@ -159,7 +158,7 @@ method="run" file="Generator.java" line="94"/>
}
// Write the start element
- writer.WriteStartElement("log4j:event", "log4j", "event", "log4net");
+ writer.EnsureNotNull().WriteStartElement("log4j:event", "log4j", "event", "log4net");
writer.WriteAttributeString("logger", loggingEvent.LoggerName);
// Calculate the timestamp as the number of milliseconds since january 1970
diff --git a/src/log4net/LogManager.cs b/src/log4net/LogManager.cs
index f92865a0..a4188d7a 100644
--- a/src/log4net/LogManager.cs
+++ b/src/log4net/LogManager.cs
@@ -23,6 +23,7 @@ using System.Reflection;
using log4net.Appender;
using log4net.Core;
using log4net.Repository;
+using log4net.Util;
namespace log4net;
@@ -32,7 +33,7 @@ namespace log4net;
/// <remarks>
/// <para>
/// This class has static methods that are used by a client to request
-/// a logger instance. The <see cref="M:GetLogger(string)"/> method is
+/// a logger instance. The <see cref="GetLogger(string)"/> method is
/// used to retrieve a logger.
/// </para>
/// <para>
@@ -70,10 +71,7 @@ public static class LogManager
/// </remarks>
/// <param name="name">The fully qualified logger name to look for.</param>
/// <returns>The logger found, or <c>null</c> if no logger could be found.</returns>
- public static ILog? Exists(string name)
- {
- return Exists(Assembly.GetCallingAssembly(), name);
- }
+ public static ILog? Exists(string name) => Exists(Assembly.GetCallingAssembly(), name);
/// <overloads>Get the currently defined loggers.</overloads>
/// <summary>
@@ -83,10 +81,7 @@ public static class LogManager
/// <para>The root logger is <b>not</b> included in the returned array.</para>
/// </remarks>
/// <returns>All the defined loggers.</returns>
- public static ILog[] GetCurrentLoggers()
- {
- return GetCurrentLoggers(Assembly.GetCallingAssembly());
- }
+ public static ILog[] GetCurrentLoggers() => GetCurrentLoggers(Assembly.GetCallingAssembly());
/// <overloads>Get or create a logger.</overloads>
/// <summary>
@@ -106,10 +101,7 @@ public static class LogManager
/// </remarks>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(string name)
- {
- return GetLogger(Assembly.GetCallingAssembly(), name);
- }
+ public static ILog GetLogger(string name) => GetLogger(Assembly.GetCallingAssembly(), name);
/// <summary>
/// Returns the named logger if it exists.
@@ -127,10 +119,7 @@ public static class LogManager
/// The logger found, or <c>null</c> if the logger doesn't exist in the specified
/// repository.
/// </returns>
- public static ILog? Exists(string repository, string name)
- {
- return WrapLogger(LoggerManager.Exists(repository, name));
- }
+ public static ILog? Exists(string repository, string name) => WrapLogger(LoggerManager.Exists(repository, name));
/// <summary>
/// Returns the named logger if it exists.
@@ -148,10 +137,7 @@ public static class LogManager
/// The logger, or <c>null</c> if the logger doesn't exist in the specified
/// assembly's repository.
/// </returns>
- public static ILog? Exists(Assembly repositoryAssembly, string name)
- {
- return WrapLogger(LoggerManager.Exists(repositoryAssembly, name));
- }
+ public static ILog? Exists(Assembly repositoryAssembly, string name) => WrapLogger(LoggerManager.Exists(repositoryAssembly, name));
/// <summary>
/// Returns all the currently defined loggers in the specified repository.
@@ -161,10 +147,7 @@ public static class LogManager
/// The root logger is <b>not</b> included in the returned array.
/// </remarks>
/// <returns>All the defined loggers.</returns>
- public static ILog[] GetCurrentLoggers(string repository)
- {
- return WrapLoggers(LoggerManager.GetCurrentLoggers(repository));
- }
+ public static ILog[] GetCurrentLoggers(string repository) => WrapLoggers(LoggerManager.GetCurrentLoggers(repository));
/// <summary>
/// Returns all the currently defined loggers in the specified assembly's repository.
@@ -174,10 +157,7 @@ public static class LogManager
/// The root logger is <b>not</b> included in the returned array.
/// </remarks>
/// <returns>All the defined loggers.</returns>
- public static ILog[] GetCurrentLoggers(Assembly repositoryAssembly)
- {
- return WrapLoggers(LoggerManager.GetCurrentLoggers(repositoryAssembly));
- }
+ public static ILog[] GetCurrentLoggers(Assembly repositoryAssembly) => WrapLoggers(LoggerManager.GetCurrentLoggers(repositoryAssembly));
/// <summary>
/// Retrieves or creates a named logger.
@@ -198,10 +178,7 @@ public static class LogManager
/// <param name="repository">The repository to lookup in.</param>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(string repository, string name)
- {
- return WrapLogger(LoggerManager.GetLogger(repository, name))!;
- }
+ public static ILog GetLogger(string repository, string name) => WrapLogger(LoggerManager.GetLogger(repository, name))!;
/// <summary>
/// Retrieves or creates a named logger.
@@ -222,26 +199,22 @@ public static class LogManager
/// <param name="repositoryAssembly">The assembly to use to look up the repository.</param>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(Assembly repositoryAssembly, string name)
- {
- return WrapLogger(LoggerManager.GetLogger(repositoryAssembly, name))!;
- }
+ public static ILog GetLogger(Assembly repositoryAssembly, string name)
+ => WrapLogger(LoggerManager.GetLogger(repositoryAssembly, name))!;
/// <summary>
- /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+ /// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Get the logger for the fully qualified name of the type specified.
/// </remarks>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(Type type)
- {
- return GetLogger(Assembly.GetCallingAssembly(), type.FullName!);
- }
+ public static ILog GetLogger(Type type)
+ => GetLogger(Assembly.GetCallingAssembly(), type.EnsureNotNull().FullName!);
/// <summary>
- /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+ /// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Gets the logger for the fully qualified name of the type specified.
@@ -249,13 +222,11 @@ public static class LogManager
/// <param name="repository">The repository to lookup in.</param>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(string repository, Type type)
- {
- return WrapLogger(LoggerManager.GetLogger(repository, type))!;
- }
+ public static ILog GetLogger(string repository, Type type)
+ => WrapLogger(LoggerManager.GetLogger(repository, type))!;
/// <summary>
- /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+ /// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Gets the logger for the fully qualified name of the type specified.
@@ -263,10 +234,8 @@ public static class LogManager
/// <param name="repositoryAssembly">The assembly to use to look up the repository.</param>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
- public static ILog GetLogger(Assembly repositoryAssembly, Type type)
- {
- return WrapLogger(LoggerManager.GetLogger(repositoryAssembly, type))!;
- }
+ public static ILog GetLogger(Assembly repositoryAssembly, Type type)
+ => WrapLogger(LoggerManager.GetLogger(repositoryAssembly, type))!;
/// <summary>
/// Shuts down the log4net system.
@@ -287,10 +256,7 @@ public static class LogManager
/// and again to a nested appender.
/// </para>
/// </remarks>
- public static void Shutdown()
- {
- LoggerManager.Shutdown();
- }
+ public static void Shutdown() => LoggerManager.Shutdown();
/// <overloads>Shutdown a logger repository.</overloads>
/// <summary>
@@ -311,10 +277,7 @@ public static class LogManager
/// and again to a nested appender.
/// </para>
/// </remarks>
- public static void ShutdownRepository()
- {
- ShutdownRepository(Assembly.GetCallingAssembly());
- }
+ public static void ShutdownRepository() => ShutdownRepository(Assembly.GetCallingAssembly());
/// <summary>
/// Shuts down the repository for the repository specified.
@@ -336,10 +299,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repository">The repository to shut down.</param>
- public static void ShutdownRepository(string repository)
- {
- LoggerManager.ShutdownRepository(repository);
- }
+ public static void ShutdownRepository(string repository) => LoggerManager.ShutdownRepository(repository);
/// <summary>
/// Shuts down the repository specified.
@@ -363,10 +323,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to look up the repository.</param>
- public static void ShutdownRepository(Assembly repositoryAssembly)
- {
- LoggerManager.ShutdownRepository(repositoryAssembly);
- }
+ public static void ShutdownRepository(Assembly repositoryAssembly) => LoggerManager.ShutdownRepository(repositoryAssembly);
/// <overloads>Reset the configuration of a repository</overloads>
/// <summary>
@@ -382,10 +339,7 @@ public static class LogManager
/// message disabling is set to its default "off" value.
/// </para>
/// </remarks>
- public static void ResetConfiguration()
- {
- ResetConfiguration(Assembly.GetCallingAssembly());
- }
+ public static void ResetConfiguration() => ResetConfiguration(Assembly.GetCallingAssembly());
/// <summary>
/// Resets all values contained in this repository instance to their defaults.
@@ -401,10 +355,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repository">The repository to reset.</param>
- public static void ResetConfiguration(string repository)
- {
- LoggerManager.ResetConfiguration(repository);
- }
+ public static void ResetConfiguration(string repository) => LoggerManager.ResetConfiguration(repository);
/// <summary>
/// Resets all values contained in this repository instance to their defaults.
@@ -420,10 +371,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to look up the repository to reset.</param>
- public static void ResetConfiguration(Assembly repositoryAssembly)
- {
- LoggerManager.ResetConfiguration(repositoryAssembly);
- }
+ public static void ResetConfiguration(Assembly repositoryAssembly) => LoggerManager.ResetConfiguration(repositoryAssembly);
/// <overloads>Get a logger repository.</overloads>
/// <summary>
@@ -432,14 +380,11 @@ public static class LogManager
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
- /// by the callers assembly (<see cref="M:Assembly.GetCallingAssembly()"/>).
+ /// by the callers assembly (<see cref="Assembly.GetCallingAssembly()"/>).
/// </para>
/// </remarks>
/// <returns>The <see cref="ILoggerRepository"/> instance for the default repository.</returns>
- public static ILoggerRepository GetRepository()
- {
- return GetRepository(Assembly.GetCallingAssembly());
- }
+ public static ILoggerRepository GetRepository() => GetRepository(Assembly.GetCallingAssembly());
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
@@ -452,10 +397,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
- public static ILoggerRepository GetRepository(string repository)
- {
- return LoggerManager.GetRepository(repository);
- }
+ public static ILoggerRepository GetRepository(string repository) => LoggerManager.GetRepository(repository);
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
@@ -468,10 +410,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to look up the repository.</param>
- public static ILoggerRepository GetRepository(Assembly repositoryAssembly)
- {
- return LoggerManager.GetRepository(repositoryAssembly);
- }
+ public static ILoggerRepository GetRepository(Assembly repositoryAssembly) => LoggerManager.GetRepository(repositoryAssembly);
/// <overloads>Create a logger repository.</overloads>
/// <summary>
@@ -484,14 +423,11 @@ public static class LogManager
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository()"/> will return
+ /// specified such that a call to <see cref="GetRepository()"/> will return
/// the same repository instance.
/// </para>
/// </remarks>
- public static ILoggerRepository CreateRepository(Type repositoryType)
- {
- return CreateRepository(Assembly.GetCallingAssembly(), repositoryType);
- }
+ public static ILoggerRepository CreateRepository(Type repositoryType) => CreateRepository(Assembly.GetCallingAssembly(), repositoryType);
/// <summary>
/// Creates a repository with the specified name.
@@ -509,10 +445,7 @@ public static class LogManager
/// <param name="repository">The name of the repository, this must be unique amongst repositories.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
- public static ILoggerRepository CreateRepository(string repository)
- {
- return LoggerManager.CreateRepository(repository);
- }
+ public static ILoggerRepository CreateRepository(string repository) => LoggerManager.CreateRepository(repository);
/// <summary>
/// Creates a repository with the specified name and repository type.
@@ -529,10 +462,7 @@ public static class LogManager
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
- public static ILoggerRepository CreateRepository(string repository, Type repositoryType)
- {
- return LoggerManager.CreateRepository(repository, repositoryType);
- }
+ public static ILoggerRepository CreateRepository(string repository, Type repositoryType) => LoggerManager.CreateRepository(repository, repositoryType);
/// <summary>
/// Creates a repository for the specified assembly and repository type.
@@ -540,7 +470,7 @@ public static class LogManager
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
- /// specified such that a call to <see cref="M:GetRepository(Assembly)"/> with the
+ /// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
@@ -549,10 +479,7 @@ public static class LogManager
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
- public static ILoggerRepository CreateRepository(Assembly repositoryAssembly, Type repositoryType)
- {
- return LoggerManager.CreateRepository(repositoryAssembly, repositoryType);
- }
+ public static ILoggerRepository CreateRepository(Assembly repositoryAssembly, Type repositoryType) => LoggerManager.CreateRepository(repositoryAssembly, repositoryType);
/// <summary>
/// Gets the list of currently defined repositories.
@@ -563,10 +490,7 @@ public static class LogManager
/// </para>
/// </remarks>
/// <returns>An array of all the known <see cref="ILoggerRepository"/> objects.</returns>
- public static ILoggerRepository[] GetAllRepositories()
- {
- return LoggerManager.GetAllRepositories();
- }
+ public static ILoggerRepository[] GetAllRepositories() => LoggerManager.GetAllRepositories();
/// <summary>
/// Flushes logging events buffered in all configured appenders in the default repository.
@@ -588,11 +512,8 @@ public static class LogManager
/// </summary>
/// <param name="logger">The logger to get the wrapper for.</param>
/// <returns>The wrapper for the logger specified.</returns>
- [return: NotNullIfNotNull("logger")]
- private static ILog? WrapLogger(ILogger? logger)
- {
- return (ILog?)_sWrapperMap.GetWrapper(logger);
- }
+ [return: NotNullIfNotNull(nameof(logger))]
+ private static ILog? WrapLogger(ILogger? logger) => (ILog?)_sWrapperMap.GetWrapper(logger);
/// <summary>
/// Looks up the wrapper objects for the loggers specified.
@@ -615,10 +536,7 @@ public static class LogManager
/// </summary>
/// <param name="logger">The logger to wrap.</param>
/// <returns>The wrapper for the logger specified.</returns>
- private static ILoggerWrapper WrapperCreationHandler(ILogger logger)
- {
- return new LogImpl(logger);
- }
+ private static LogImpl WrapperCreationHandler(ILogger logger) => new(logger);
/// <summary>
/// The wrapper map to use to hold the <see cref="LogImpl"/> objects.
diff --git a/src/log4net/ObjectRenderer/DefaultRenderer.cs b/src/log4net/ObjectRenderer/DefaultRenderer.cs
index cf62ea94..62cd98c7 100644
--- a/src/log4net/ObjectRenderer/DefaultRenderer.cs
+++ b/src/log4net/ObjectRenderer/DefaultRenderer.cs
@@ -54,7 +54,7 @@ public sealed class DefaultRenderer : IObjectRenderer
/// The <paramref name="rendererMap"/> parameter is
/// provided to lookup and render other objects. This is
/// very useful where <paramref name="obj"/> contains
- /// nested objects of unknown type. The <see cref="M:RendererMap.FindAndRender(object)"/>
+ /// nested objects of unknown type. The <see cref="RendererMap.FindAndRender(object)"/>
/// method can be used to render these objects.
/// </para>
/// <para>
@@ -128,10 +128,8 @@ public sealed class DefaultRenderer : IObjectRenderer
/// </remarks>
public void RenderObject(RendererMap rendererMap, object? obj, TextWriter writer)
{
- if (rendererMap is null)
- {
- throw new ArgumentNullException(nameof(rendererMap));
- }
+ rendererMap.EnsureNotNull();
+ writer.EnsureNotNull();
if (obj is null)
{
diff --git a/src/log4net/ObjectRenderer/IObjectRenderer.cs b/src/log4net/ObjectRenderer/IObjectRenderer.cs
index 69f3b60d..64f13d19 100644
--- a/src/log4net/ObjectRenderer/IObjectRenderer.cs
+++ b/src/log4net/ObjectRenderer/IObjectRenderer.cs
@@ -51,7 +51,7 @@ public interface IObjectRenderer
/// The <paramref name="rendererMap"/> parameter is
/// provided to lookup and render other objects. This is
/// very useful where <paramref name="obj"/> contains
- /// nested objects of unknown type. The <see cref="M:RendererMap.FindAndRender(object, TextWriter)"/>
+ /// nested objects of unknown type. The <see cref="RendererMap.FindAndRender(object, TextWriter)"/>
/// method can be used to render these objects.
/// </para>
/// </remarks>
diff --git a/src/log4net/ObjectRenderer/RendererMap.cs b/src/log4net/ObjectRenderer/RendererMap.cs
index 49237a67..e005a96b 100644
--- a/src/log4net/ObjectRenderer/RendererMap.cs
+++ b/src/log4net/ObjectRenderer/RendererMap.cs
@@ -30,7 +30,7 @@ namespace log4net.ObjectRenderer;
/// </summary>
/// <remarks>
/// <para>
-/// The <see cref="M:FindAndRender(object)"/> method is used to render an
+/// The <see cref="FindAndRender(object)"/> method is used to render an
/// <c>object</c> using the appropriate renderers defined in this map,
/// using a default renderer if no custom renderer is defined for a type.
/// </para>
@@ -52,7 +52,7 @@ public class RendererMap
/// <remarks>
/// <para>
/// This is a convenience method used to render an object to a string.
- /// The alternative method <see cref="M:FindAndRender(object,TextWriter)"/>
+ /// The alternative method <see cref="FindAndRender(object,TextWriter)"/>
/// should be used when streaming output to a <see cref="TextWriter"/>.
/// </para>
/// </remarks>
@@ -78,7 +78,7 @@ public class RendererMap
/// <para>
/// Find the appropriate renderer for the type of the
/// <paramref name="obj"/> parameter. This is accomplished by calling the
- /// <see cref="M:Get(Type)"/> method. Once a renderer is found, it is
+ /// <see cref="Get(Type)"/> method. Once a renderer is found, it is
/// applied on the object <paramref name="obj"/> and the result is returned
/// as a <see cref="string"/>.
/// </para>
@@ -141,7 +141,7 @@ public class RendererMap
/// Gets the renderer for the specified object type.
/// </param>
/// <param>
- /// Syntactic sugar method that calls <see cref="M:Get(Type)"/>
+ /// Syntactic sugar method that calls <see cref="Get(Type)"/>
/// with the type of the object parameter.
/// </param>
/// </remarks>
@@ -162,13 +162,8 @@ public class RendererMap
/// <returns>The renderer for the specified type, or <see cref="DefaultRenderer"/> if no specific renderer has been defined.</returns>
public IObjectRenderer Get(Type type)
{
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
// Check cache
- if (!_cache.TryGetValue(type, out IObjectRenderer? result))
+ if (!_cache.TryGetValue(type.EnsureNotNull(), out IObjectRenderer? result))
{
for (Type? cur = type; cur is not null; cur = cur.BaseType)
{
@@ -235,16 +230,7 @@ public class RendererMap
/// <param name="renderer">The renderer for <paramref name="typeToRender"/>.</param>
public void Put(Type typeToRender, IObjectRenderer renderer)
{
- if (typeToRender is null)
- {
- throw new ArgumentNullException(nameof(typeToRender));
- }
- if (renderer is null)
- {
- throw new ArgumentNullException(nameof(renderer));
- }
-
_cache.Clear();
- _map[typeToRender] = renderer;
+ _map[typeToRender.EnsureNotNull()] = renderer.EnsureNotNull();
}
}
diff --git a/src/log4net/Plugin/PluginCollection.cs b/src/log4net/Plugin/PluginCollection.cs
index cf21976a..bd87fe51 100644
--- a/src/log4net/Plugin/PluginCollection.cs
+++ b/src/log4net/Plugin/PluginCollection.cs
@@ -94,44 +94,48 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// Initializes a new instance of the <c>PluginCollection</c> class
/// that contains elements copied from the specified <c>PluginCollection</c>.
/// </summary>
- /// <param name="c">The <c>PluginCollection</c> whose elements are copied to the new collection.</param>
- public PluginCollection(PluginCollection c)
+ /// <param name="collection">The <c>PluginCollection</c> whose elements are copied to the new collection.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public PluginCollection(PluginCollection collection)
{
- _array = new IPlugin[c.Count];
- AddRange(c);
+ _array = new IPlugin[collection.EnsureNotNull().Count];
+ AddRange(collection);
}
/// <summary>
/// Initializes a new instance of the <c>PluginCollection</c> class
/// that contains elements copied from the specified <see cref="IPlugin"/> array.
/// </summary>
- /// <param name="a">The <see cref="IPlugin"/> array whose elements are copied to the new list.</param>
- public PluginCollection(IPlugin[] a)
+ /// <param name="array">The <see cref="IPlugin"/> array whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public PluginCollection(IPlugin[] array)
{
- _array = new IPlugin[a.Length];
- AddRange(a);
+ _array = new IPlugin[array.EnsureNotNull().Length];
+ AddRange(array);
}
/// <summary>
/// Initializes a new instance of the <c>PluginCollection</c> class
/// that contains elements copied from the specified <see cref="IPlugin"/> collection.
/// </summary>
- /// <param name="col">The <see cref="IPlugin"/> collection whose elements are copied to the new list.</param>
- public PluginCollection(ICollection col)
+ /// <param name="collection">The <see cref="IPlugin"/> collection whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public PluginCollection(ICollection collection)
{
- _array = new IPlugin[col.Count];
- AddRange(col);
+ _array = new IPlugin[collection.EnsureNotNull().Count];
+ AddRange(collection);
}
/// <summary>
/// Initializes a new instance of the <c>PluginCollection</c> class
/// that contains elements copied from the specified <see cref="IPlugin"/> collection.
/// </summary>
- /// <param name="col">The <see cref="IPlugin"/> collection whose elements are copied to the new list.</param>
- public PluginCollection(ICollection<IPlugin> col)
+ /// <param name="collection">The <see cref="IPlugin"/> collection whose elements are copied to the new list.</param>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
+ public PluginCollection(ICollection<IPlugin> collection)
{
- _array = new IPlugin[col.Count];
- AddRange(col);
+ _array = new IPlugin[collection.EnsureNotNull().Count];
+ AddRange(collection);
}
/// <summary>
@@ -151,10 +155,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// Allow subclasses to avoid our default constructors
/// </summary>
/// <exclude/>
- protected internal PluginCollection(Tag _)
- {
- _array = Array.Empty<IPlugin>();
- }
+ protected internal PluginCollection(Tag _) => _array = Array.Empty<IPlugin>();
/// <summary>
/// Gets the number of elements actually contained in the <c>PluginCollection</c>.
@@ -176,12 +177,12 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
public virtual void CopyTo(IPlugin[] array, int start)
{
- if (_count > array.GetUpperBound(0) + 1 - start)
+ if (_count > array.EnsureNotNull().GetUpperBound(0) + 1 - start)
{
throw new ArgumentException("Destination array was not long enough.");
}
- Array.Copy(this._array, 0, array, start, _count);
+ Array.Copy(_array, 0, array, start, _count);
}
/// <summary>
@@ -205,7 +206,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero.</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="PluginCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual IPlugin this[int index]
{
@@ -310,7 +311,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="PluginCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual void Insert(int index, IPlugin item)
{
@@ -356,7 +357,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="index"/> is less than zero.</para>
/// <para>-or-</para>
- /// <para><paramref name="index"/> is equal to or greater than <see cref="PluginCollection.Count"/>.</para>
+ /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
public virtual void RemoveAt(int index)
{
@@ -430,17 +431,17 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of another <c>PluginCollection</c> to the current <c>PluginCollection</c>.
/// </summary>
- /// <param name="x">The <c>PluginCollection</c> whose elements should be added to the end of the current <c>PluginCollection</c>.</param>
- /// <returns>The new <see cref="PluginCollection.Count"/> of the <c>PluginCollection</c>.</returns>
- public virtual int AddRange(PluginCollection x)
+ /// <param name="collection">The <c>PluginCollection</c> whose elements should be added to the end of the current <c>PluginCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>PluginCollection</c>.</returns>
+ public virtual int AddRange(PluginCollection collection)
{
- if (_count + x.Count >= _array.Length)
+ if (_count + collection.EnsureNotNull().Count >= _array.Length)
{
- EnsureCapacity(_count + x.Count);
+ EnsureCapacity(_count + collection.Count);
}
- Array.Copy(x._array, 0, _array, _count, x.Count);
- _count += x.Count;
+ Array.Copy(collection._array, 0, _array, _count, collection.Count);
+ _count += collection.Count;
_version++;
return _count;
@@ -449,17 +450,17 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of a <see cref="IPlugin"/> array to the current <c>PluginCollection</c>.
/// </summary>
- /// <param name="x">The <see cref="IPlugin"/> array whose elements should be added to the end of the <c>PluginCollection</c>.</param>
- /// <returns>The new <see cref="PluginCollection.Count"/> of the <c>PluginCollection</c>.</returns>
- public virtual int AddRange(IPlugin[] x)
+ /// <param name="array">The <see cref="IPlugin"/> array whose elements should be added to the end of the <c>PluginCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>PluginCollection</c>.</returns>
+ public virtual int AddRange(IPlugin[] array)
{
- if (_count + x.Length >= _array.Length)
+ if (_count + array.EnsureNotNull().Length >= _array.Length)
{
- EnsureCapacity(_count + x.Length);
+ EnsureCapacity(_count + array.Length);
}
- Array.Copy(x, 0, _array, _count, x.Length);
- _count += x.Length;
+ Array.Copy(array, 0, _array, _count, array.Length);
+ _count += array.Length;
_version++;
return _count;
@@ -468,16 +469,16 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of a <see cref="IPlugin"/> collection to the current <c>PluginCollection</c>.
/// </summary>
- /// <param name="col">The <see cref="IPlugin"/> collection whose elements should be added to the end of the <c>PluginCollection</c>.</param>
- /// <returns>The new <see cref="PluginCollection.Count"/> of the <c>PluginCollection</c>.</returns>
- public virtual int AddRange(ICollection col)
+ /// <param name="collection">The <see cref="IPlugin"/> collection whose elements should be added to the end of the <c>PluginCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>PluginCollection</c>.</returns>
+ public virtual int AddRange(ICollection collection)
{
- if (_count + col.Count >= _array.Length)
+ if (_count + collection.EnsureNotNull().Count >= _array.Length)
{
- EnsureCapacity(_count + col.Count);
+ EnsureCapacity(_count + collection.Count);
}
- foreach (object item in col)
+ foreach (object item in collection)
{
Add((IPlugin)item);
}
@@ -488,16 +489,16 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <summary>
/// Adds the elements of a <see cref="IPlugin"/> collection to the current <c>PluginCollection</c>.
/// </summary>
- /// <param name="col">The <see cref="IPlugin"/> collection whose elements should be added to the end of the <c>PluginCollection</c>.</param>
- /// <returns>The new <see cref="PluginCollection.Count"/> of the <c>PluginCollection</c>.</returns>
- public virtual int AddRange(ICollection<IPlugin> col)
+ /// <param name="collection">The <see cref="IPlugin"/> collection whose elements should be added to the end of the <c>PluginCollection</c>.</param>
+ /// <returns>The new <see cref="Count"/> of the <c>PluginCollection</c>.</returns>
+ public virtual int AddRange(ICollection<IPlugin> collection)
{
- if (_count + col.Count >= _array.Length)
+ if (_count + collection.EnsureNotNull().Count >= _array.Length)
{
- EnsureCapacity(_count + col.Count);
+ EnsureCapacity(_count + collection.Count);
}
- foreach (IPlugin item in col)
+ foreach (IPlugin item in collection)
{
Add(item);
}
@@ -513,18 +514,18 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="i"/> is less than zero.</para>
/// <para>-or-</para>
- /// <para><paramref name="i"/> is equal to or greater than <see cref="PluginCollection.Count"/>.</para>
+ /// <para><paramref name="i"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
private void ValidateIndex(int i) => ValidateIndex(i, false);
/// <exception cref="ArgumentOutOfRangeException">
/// <para><paramref name="i"/> is less than zero.</para>
/// <para>-or-</para>
- /// <para><paramref name="i"/> is equal to or greater than <see cref="PluginCollection.Count"/>.</para>
+ /// <para><paramref name="i"/> is equal to or greater than <see cref="Count"/>.</para>
/// </exception>
private void ValidateIndex(int i, bool allowEqualEnd)
{
- int max = (allowEqualEnd) ? (_count) : (_count - 1);
+ int max = allowEqualEnd ? _count : (_count - 1);
if (i < 0 || i > max)
{
throw SystemInfo.CreateArgumentOutOfRangeException(nameof(i), i, $"Index was out of range. Must be non-negative and less than the size of the collection. [{i}] Specified argument was out of the range of valid values.");
@@ -533,7 +534,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
private void EnsureCapacity(int min)
{
- int newCapacity = ((_array.Length == 0) ? DefaultCapacity : _array.Length * 2);
+ int newCapacity = (_array.Length == 0) ? DefaultCapacity : _array.Length * 2;
if (newCapacity < min)
{
newCapacity = min;
@@ -608,7 +609,7 @@ public class PluginCollection : ICollection, IList, IEnumerable, ICloneable
}
++_index;
- return (_index < _collection.Count);
+ return _index < _collection.Count;
}
/// <summary>
diff --git a/src/log4net/Plugin/PluginMap.cs b/src/log4net/Plugin/PluginMap.cs
index 3dc039bf..2fdf58a3 100644
--- a/src/log4net/Plugin/PluginMap.cs
+++ b/src/log4net/Plugin/PluginMap.cs
@@ -20,12 +20,14 @@
using System;
using System.Collections.Concurrent;
using log4net.Repository;
+using log4net.Util;
namespace log4net.Plugin;
/// <summary>
/// Map of repository plugins.
/// </summary>
+/// <param name="repository">The repository that the plugins should be attached to.</param>
/// <remarks>
/// <para>
/// This class is a name keyed map of the plugins that are
@@ -34,23 +36,8 @@ namespace log4net.Plugin;
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
-public sealed class PluginMap
+public sealed class PluginMap(ILoggerRepository repository)
{
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="repository">The repository that the plugins should be attached to.</param>
- /// <remarks>
- /// <para>
- /// Initialize a new instance of the <see cref="PluginMap" /> class with a
- /// repository that the plugins should be attached to.
- /// </para>
- /// </remarks>
- public PluginMap(ILoggerRepository repository)
- {
- this._repository = repository;
- }
-
/// <summary>
/// Gets a <see cref="IPlugin" /> by name.
/// </summary>
@@ -63,12 +50,7 @@ public sealed class PluginMap
{
get
{
- if (name is null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- _mapName2Plugin.TryGetValue(name, out IPlugin? plugin);
+ _mapName2Plugin.TryGetValue(name.EnsureNotNull(), out IPlugin? plugin);
return plugin;
}
}
@@ -77,7 +59,7 @@ public sealed class PluginMap
/// Gets all possible plugins as a list of <see cref="IPlugin" /> objects.
/// </summary>
/// <value>All possible plugins as a list of <see cref="IPlugin" /> objects.</value>
- public PluginCollection AllPlugins => new PluginCollection(_mapName2Plugin.Values);
+ public PluginCollection AllPlugins => new(_mapName2Plugin.Values);
/// <summary>
/// Adds a <see cref="IPlugin" /> to the map.
@@ -96,13 +78,8 @@ public sealed class PluginMap
/// </remarks>
public void Add(IPlugin plugin)
{
- if (plugin is null)
- {
- throw new ArgumentNullException(nameof(plugin));
- }
-
IPlugin? curPlugin = null;
- _mapName2Plugin.AddOrUpdate(plugin.Name, plugin, (_, existingPlugin) =>
+ _mapName2Plugin.AddOrUpdate(plugin.EnsureNotNull().Name, plugin, (_, existingPlugin) =>
{
curPlugin = existingPlugin;
return plugin;
@@ -112,22 +89,14 @@ public sealed class PluginMap
curPlugin?.Shutdown();
// Attach new plugin to repository
- plugin.Attach(_repository);
+ plugin.Attach(repository);
}
/// <summary>
/// Removes an <see cref="IPlugin" /> from the map.
/// </summary>
/// <param name="plugin">The <see cref="IPlugin" /> to remove from the map.</param>
- public void Remove(IPlugin plugin)
- {
- if (plugin is null)
- {
- throw new ArgumentNullException(nameof(plugin));
- }
- _mapName2Plugin.TryRemove(plugin.Name, out _);
- }
+ public void Remove(IPlugin plugin) => _mapName2Plugin.TryRemove(plugin.EnsureNotNull().Name, out _);
private readonly ConcurrentDictionary<string, IPlugin> _mapName2Plugin = new(StringComparer.Ordinal);
- private readonly ILoggerRepository _repository;
}
diff --git a/src/log4net/Repository/Hierarchy/Hierarchy.cs b/src/log4net/Repository/Hierarchy/Hierarchy.cs
index fc3b4a43..b98d12b2 100644
--- a/src/log4net/Repository/Hierarchy/Hierarchy.cs
+++ b/src/log4net/Repository/Hierarchy/Hierarchy.cs
@@ -21,6 +21,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using log4net.Appender;
@@ -34,6 +35,8 @@ namespace log4net.Repository.Hierarchy;
/// </summary>
/// <param name="sender">The <see cref="Hierarchy"/> in which the <see cref="Logger"/> has been created.</param>
/// <param name="e">The <see cref="LoggerCreationEventArgs"/> event args that hold the <see cref="Logger"/> instance that has been created.</param>
+[SuppressMessage("Design", "CA1003:Use generic event handler instances")]
+[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public delegate void LoggerCreationEventHandler(object sender, LoggerCreationEventArgs e);
/// <summary>
@@ -79,10 +82,14 @@ public class LoggerCreationEventArgs(Logger log) : EventArgs
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
-public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator, IXmlRepositoryConfigurator
+/// <param name="properties">The properties to pass to this repository.</param>
+/// <param name="loggerFactory">The factory to use to create new logger instances.</param>
+[SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces")]
+public class Hierarchy(PropertiesDictionary properties, ILoggerFactory loggerFactory)
+ : LoggerRepositorySkeleton(properties), IBasicRepositoryConfigurator, IXmlRepositoryConfigurator
{
private readonly ConcurrentDictionary<LoggerKey, object> _loggers = new(LoggerKey.ComparerInstance);
- private ILoggerFactory _defaultFactory;
+ private ILoggerFactory _defaultFactory = loggerFactory.EnsureNotNull();
private Logger? _rootLogger;
/// <summary>
@@ -101,14 +108,16 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// <summary>
/// Default constructor
/// </summary>
- public Hierarchy() : this(new DefaultLoggerFactory())
+ public Hierarchy()
+ : this(new DefaultLoggerFactory())
{ }
/// <summary>
/// Construct with properties
/// </summary>
/// <param name="properties">The properties to pass to this repository.</param>
- public Hierarchy(PropertiesDictionary properties) : this(properties, new DefaultLoggerFactory())
+ public Hierarchy(PropertiesDictionary properties)
+ : this(properties, new DefaultLoggerFactory())
{ }
/// <summary>
@@ -118,14 +127,6 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
public Hierarchy(ILoggerFactory loggerFactory) : this([], loggerFactory)
{ }
- /// <summary>
- /// Construct with properties and a logger factory
- /// </summary>
- /// <param name="properties">The properties to pass to this repository.</param>
- /// <param name="loggerFactory">The factory to use to create new logger instances.</param>
- public Hierarchy(PropertiesDictionary properties, ILoggerFactory loggerFactory)
- : base(properties) => _defaultFactory = loggerFactory.EnsureNotNull();
-
/// <summary>
/// Has no appender warning been emitted
/// </summary>
@@ -306,7 +307,7 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// This method should not normally be used to log.
/// The <see cref="ILog"/> interface should be used
/// for routine logging. This interface can be obtained
- /// using the <see cref="M:log4net.LogManager.GetLogger(string)"/> method.
+ /// using the <see cref="LogManager.GetLogger(string)"/> method.
/// </para>
/// <para>
/// The <paramref name="logEvent" /> is delivered to the appropriate logger and
@@ -328,7 +329,7 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// <returns>An array containing all the currently configured appenders</returns>
/// <remarks>
/// <para>
- /// Returns all the <see cref="log4net.Appender.IAppender"/> instances that are currently configured.
+ /// Returns all the <see cref="IAppender"/> instances that are currently configured.
/// All the loggers are searched for appenders. The appenders may also be containers
/// for appenders and these are also searched for additional loggers.
/// </para>
@@ -336,7 +337,7 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// The list returned is unordered but does not contain duplicates.
/// </para>
/// </remarks>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0305:Simplify collection initialization")]
+ [SuppressMessage("Style", "IDE0305:Simplify collection initialization")]
public override IAppender[] GetAppenders()
{
HashSet<IAppender> appenderList = [];
@@ -395,12 +396,13 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// <remarks>
/// <para>
/// This method provides the same functionality as the
- /// <see cref="M:IBasicRepositoryConfigurator.Configure(IAppender)"/> method implemented
+ /// <see cref="IBasicRepositoryConfigurator.Configure(IAppender)"/> method implemented
/// on this object, but it is protected and therefore can be called by subclasses.
/// </para>
/// </remarks>
protected void BasicRepositoryConfigure(params IAppender[] appenders)
{
+ appenders.EnsureNotNull();
List<LogLog> configurationMessages = [];
using (new LogLog.LogReceivedAdapter(configurationMessages))
@@ -432,7 +434,7 @@ public class Hierarchy : LoggerRepositorySkeleton, IBasicRepositoryConfigurator,
/// <remarks>
/// <para>
/// This method provides the same functionality as the
- /// <see cref="M:IBasicRepositoryConfigurator.Configure(IAppender)"/> method implemented
+ /// <see cref="IBasicRepositoryConfigurator.Configure(IAppender)"/> method implemented
/// on this object, but it is protected and therefore can be called by subclasses.
/// </para>
/// </remarks>
diff --git a/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs b/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
index e725032e..1ec9c1a9 100644
--- a/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
+++ b/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
@@ -35,14 +35,10 @@ namespace log4net.Repository.Hierarchy;
/// <summary>
/// Initializes the log4net environment using an XML DOM.
/// </summary>
-/// <remarks>
-/// <para>
-/// Configures a <see cref="Hierarchy"/> using an XML DOM.
-/// </para>
-/// </remarks>
+/// <param name="hierarchy">The hierarchy to build.</param>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
-public class XmlHierarchyConfigurator
+public class XmlHierarchyConfigurator(Hierarchy hierarchy)
{
private enum ConfigUpdateMode
{
@@ -50,21 +46,6 @@ public class XmlHierarchyConfigurator
Overwrite
}
- /// <summary>
- /// Construct the configurator for a hierarchy
- /// </summary>
- /// <param name="hierarchy">The hierarchy to build.</param>
- /// <remarks>
- /// <para>
- /// Initializes a new instance of the <see cref="XmlHierarchyConfigurator" /> class
- /// with the specified <see cref="Hierarchy" />.
- /// </para>
- /// </remarks>
- public XmlHierarchyConfigurator(Hierarchy hierarchy)
- {
- this._hierarchy = hierarchy;
- }
-
/// <summary>
/// Configure the hierarchy by parsing a DOM tree of XML elements.
/// </summary>
@@ -161,7 +142,7 @@ public class XmlHierarchyConfigurator
if (configUpdateMode == ConfigUpdateMode.Overwrite)
{
// Reset to original unset configuration
- _hierarchy.ResetConfiguration();
+ hierarchy.ResetConfiguration();
LogLog.Debug(_declaringType, "Configuration reset before reading config.");
}
@@ -201,7 +182,7 @@ public class XmlHierarchyConfigurator
else
{
// Read the param tags and set properties on the hierarchy
- SetParameter(currentElement, _hierarchy);
+ SetParameter(currentElement, hierarchy);
}
}
}
@@ -213,7 +194,7 @@ public class XmlHierarchyConfigurator
{
if (ConvertStringTo(typeof(Level), thresholdStr) is Level thresholdLevel)
{
- _hierarchy.Threshold = thresholdLevel;
+ hierarchy.Threshold = thresholdLevel;
}
else
{
@@ -366,7 +347,7 @@ public class XmlHierarchyConfigurator
// Setting up a logger needs to be an atomic operation, in order
// to protect potential log operations while logger
// configuration is in progress.
- if (_hierarchy.GetLogger(loggerName) is Logger log)
+ if (hierarchy.GetLogger(loggerName) is Logger log)
{
lock (log)
{
@@ -390,7 +371,7 @@ public class XmlHierarchyConfigurator
/// </remarks>
protected void ParseRoot(XmlElement rootElement)
{
- Logger root = _hierarchy.Root;
+ Logger root = hierarchy.Root;
// logger configuration needs to be atomic
lock (root)
{
@@ -474,7 +455,7 @@ public class XmlHierarchyConfigurator
try
{
- _hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true)!, renderer);
+ hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true)!, renderer);
}
catch (Exception e) when (!e.IsFatal())
{
@@ -546,6 +527,7 @@ public class XmlHierarchyConfigurator
/// string argument and return a value that can be used to
/// set the property.
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
protected void SetParameter(XmlElement element, object target)
{
// Get the property name
@@ -871,7 +853,7 @@ public class XmlHierarchyConfigurator
if (typeof(Level) == type)
{
// Property wants a level
- Level? levelValue = _hierarchy.LevelMap[value];
+ Level? levelValue = hierarchy.LevelMap[value];
if (levelValue is null)
{
@@ -1001,7 +983,7 @@ public class XmlHierarchyConfigurator
}
}
- private static IDictionary CreateCaseInsensitiveWrapper(IDictionary dict)
+ private static Hashtable CreateCaseInsensitiveWrapper(IDictionary dict)
{
Hashtable hash = SystemInfo.CreateCaseInsensitiveHashtable();
foreach (DictionaryEntry entry in dict)
@@ -1047,11 +1029,6 @@ public class XmlHierarchyConfigurator
/// </summary>
private readonly Dictionary<string, IAppender> _appenderBag = new(StringComparer.Ordinal);
- /// <summary>
- /// The Hierarchy being configured.
- /// </summary>
- private readonly Hierarchy _hierarchy;
-
/// <summary>
/// The fully qualified type of the XmlHierarchyConfigurator class.
/// </summary>
diff --git a/src/log4net/Repository/ILoggerRepository.cs b/src/log4net/Repository/ILoggerRepository.cs
index 529d436a..0614e393 100644
--- a/src/log4net/Repository/ILoggerRepository.cs
+++ b/src/log4net/Repository/ILoggerRepository.cs
@@ -32,6 +32,8 @@ namespace log4net.Repository;
/// </summary>
/// <param name="sender">The <see cref="ILoggerRepository"/> that is shutting down.</param>
/// <param name="e">Empty event args</param>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1003:Use generic event handler instances")]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public delegate void LoggerRepositoryShutdownEventHandler(object sender, EventArgs e);
/// <summary>
@@ -39,6 +41,8 @@ public delegate void LoggerRepositoryShutdownEventHandler(object sender, EventAr
/// </summary>
/// <param name="sender">The <see cref="ILoggerRepository"/> that has had its configuration reset.</param>
/// <param name="e">Empty event args</param>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1003:Use generic event handler instances")]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public delegate void LoggerRepositoryConfigurationResetEventHandler(object sender, EventArgs e);
/// <summary>
@@ -46,6 +50,8 @@ public delegate void LoggerRepositoryConfigurationResetEventHandler(object sende
/// </summary>
/// <param name="sender">The <see cref="ILoggerRepository"/> that has had its configuration changed.</param>
/// <param name="e">Empty event arguments.</param>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1003:Use generic event handler instances")]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public delegate void LoggerRepositoryConfigurationChangedEventHandler(object sender, EventArgs e);
/// <summary>
@@ -121,7 +127,7 @@ public interface ILoggerRepository
/// lost.
/// </para>
/// <para>
- /// The <see cref="M:Shutdown()"/> method is careful to close nested
+ /// The <see cref="Shutdown()"/> method is careful to close nested
/// appenders before closing regular appenders. This allows
/// configurations where a regular appender is attached to a logger
/// and again to a nested appender.
@@ -149,7 +155,7 @@ public interface ILoggerRepository
/// This method should not normally be used to log.
/// The <see cref="ILog"/> interface should be used
/// for routine logging. This interface can be obtained
- /// using the <see cref="M:log4net.LogManager.GetLogger(string)"/> method.
+ /// using the <see cref="log4net.LogManager.GetLogger(string)"/> method.
/// </para>
/// <para>
/// The <c>logEvent</c> is delivered to the appropriate logger and
@@ -167,6 +173,7 @@ public interface ILoggerRepository
/// Collection of internal messages captured during the most
/// recent configuration process.
/// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only")]
ICollection ConfigurationMessages { get; set; }
/// <summary>
diff --git a/src/log4net/Repository/LoggerRepositorySkeleton.cs b/src/log4net/Repository/LoggerRepositorySkeleton.cs
index 3e24702c..94b16149 100644
--- a/src/log4net/Repository/LoggerRepositorySkeleton.cs
+++ b/src/log4net/Repository/LoggerRepositorySkeleton.cs
@@ -272,7 +272,7 @@ public abstract class LoggerRepositorySkeleton : ILoggerRepository, IFlushable
/// This method should not normally be used to log.
/// The <see cref="ILog"/> interface should be used
/// for routine logging. This interface can be obtained
- /// using the <see cref="M:log4net.LogManager.GetLogger(string)"/> method.
+ /// using the <see cref="log4net.LogManager.GetLogger(string)"/> method.
/// </para>
/// <para>
/// The <c>logEvent</c> is delivered to the appropriate logger and
@@ -408,19 +408,8 @@ public abstract class LoggerRepositorySkeleton : ILoggerRepository, IFlushable
/// Adds an object renderer for a specific class.
/// </para>
/// </remarks>
- public virtual void AddRenderer(Type typeToRender, IObjectRenderer rendererInstance)
- {
- if (typeToRender is null)
- {
- throw new ArgumentNullException(nameof(typeToRender));
- }
- if (rendererInstance is null)
- {
- throw new ArgumentNullException(nameof(rendererInstance));
- }
-
- _rendererMap.Put(typeToRender, rendererInstance);
- }
+ public virtual void AddRenderer(Type typeToRender, IObjectRenderer rendererInstance)
+ => _rendererMap.Put(typeToRender.EnsureNotNull(), rendererInstance.EnsureNotNull());
/// <summary>
/// Notify the registered listeners that the repository is shutting down
diff --git a/src/log4net/Util/AppenderAttachedImpl.cs b/src/log4net/Util/AppenderAttachedImpl.cs
index dd8a3eef..f5d9e516 100644
--- a/src/log4net/Util/AppenderAttachedImpl.cs
+++ b/src/log4net/Util/AppenderAttachedImpl.cs
@@ -63,10 +63,7 @@ public class AppenderAttachedImpl : IAppenderAttachable
/// </remarks>
public int AppendLoopOnAppenders(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
// appenderList is null when empty
if (_appenderList is null)
@@ -103,11 +100,7 @@ public class AppenderAttachedImpl : IAppenderAttachable
/// </remarks>
public int AppendLoopOnAppenders(LoggingEvent[] loggingEvents)
{
- if (loggingEvents is null)
- {
- throw new ArgumentNullException(nameof(loggingEvents));
- }
- if (loggingEvents.Length == 0)
+ if (loggingEvents.EnsureNotNull().Length == 0)
{
throw new ArgumentException($"{nameof(loggingEvents)} array must not be empty", nameof(loggingEvents));
}
diff --git a/src/log4net/Util/ConverterInfo.cs b/src/log4net/Util/ConverterInfo.cs
index 7dbea2a4..0a122f6e 100644
--- a/src/log4net/Util/ConverterInfo.cs
+++ b/src/log4net/Util/ConverterInfo.cs
@@ -50,9 +50,9 @@ public sealed class ConverterInfo
/// <param name="entry"></param>
public void AddProperty(PropertyEntry entry)
{
- if (entry.Key is not null)
+ if (entry.EnsureNotNull().Key is string key)
{
- Properties[entry.Key] = entry.Value;
+ Properties[key] = entry.Value;
}
}
diff --git a/src/log4net/Util/CyclicBuffer.cs b/src/log4net/Util/CyclicBuffer.cs
index 46dc8bfe..3ae5ae1f 100644
--- a/src/log4net/Util/CyclicBuffer.cs
+++ b/src/log4net/Util/CyclicBuffer.cs
@@ -35,6 +35,8 @@ namespace log4net.Util;
/// <author>Gert Driesen</author>
public class CyclicBuffer
{
+ private readonly object _syncRoot = new();
+
/// <summary>
/// Constructor
/// </summary>
@@ -53,7 +55,7 @@ public class CyclicBuffer
throw SystemInfo.CreateArgumentOutOfRangeException(nameof(maxSize), maxSize, $"Parameter: {nameof(maxSize)}, Value: [{maxSize}] out of range. A positive integer is required.");
}
- this._maxSize = maxSize;
+ _maxSize = maxSize;
_events = new LoggingEvent[maxSize];
_first = 0;
_last = 0;
@@ -74,12 +76,9 @@ public class CyclicBuffer
/// </remarks>
public LoggingEvent? Append(LoggingEvent loggingEvent)
{
- if (loggingEvent is null)
- {
- throw new ArgumentNullException(nameof(loggingEvent));
- }
+ loggingEvent.EnsureNotNull();
- lock (this)
+ lock (_syncRoot)
{
// save the discarded event
LoggingEvent? discardedLoggingEvent = _events[_last];
@@ -105,11 +104,8 @@ public class CyclicBuffer
// Space remaining
return null;
}
- else
- {
- // Buffer is full and discarding an event
- return discardedLoggingEvent;
- }
+ // Buffer is full and discarding an event
+ return discardedLoggingEvent;
}
}
@@ -125,7 +121,7 @@ public class CyclicBuffer
/// </remarks>
public LoggingEvent? PopOldest()
{
- lock (this)
+ lock (_syncRoot)
{
LoggingEvent? ret = null;
if (_numElems > 0)
@@ -153,7 +149,7 @@ public class CyclicBuffer
/// </remarks>
public LoggingEvent[] PopAll()
{
- lock (this)
+ lock (_syncRoot)
{
LoggingEvent[] ret = new LoggingEvent[_numElems];
@@ -186,7 +182,7 @@ public class CyclicBuffer
/// </remarks>
public void Clear()
{
- lock (this)
+ lock (_syncRoot)
{
// Set all the elements to null
Array.Clear(_events, 0, _events.Length);
@@ -213,7 +209,7 @@ public class CyclicBuffer
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="newSize"/> argument is not a positive integer.</exception>
public void Resize(int newSize)
{
- lock(this)
+ lock (syncRoot)
{
if (newSize < 0)
{
@@ -269,7 +265,7 @@ public class CyclicBuffer
{
get
{
- lock (this)
+ lock (_syncRoot)
{
if (i < 0 || i >= _numElems)
{
@@ -294,7 +290,7 @@ public class CyclicBuffer
{
get
{
- lock (this)
+ lock (_syncRoot)
{
return _maxSize;
}
@@ -322,7 +318,7 @@ public class CyclicBuffer
{
get
{
- lock (this)
+ lock (_syncRoot)
{
return _numElems;
}
diff --git a/src/log4net/Util/LevelMapping.cs b/src/log4net/Util/LevelMapping.cs
index bfa530d1..9958d87d 100644
--- a/src/log4net/Util/LevelMapping.cs
+++ b/src/log4net/Util/LevelMapping.cs
@@ -46,9 +46,9 @@ public sealed class LevelMapping : IOptionHandler
/// </remarks>
public void Add(LevelMappingEntry entry)
{
- if (entry.Level is not null)
+ if (entry.EnsureNotNull().Level is Level level)
{
- _entries[entry.Level] = entry;
+ _entries[level] = entry;
}
}
diff --git a/src/log4net/Util/LogicalThreadContextStack.cs b/src/log4net/Util/LogicalThreadContextStack.cs
index 9374f491..0e067db8 100644
--- a/src/log4net/Util/LogicalThreadContextStack.cs
+++ b/src/log4net/Util/LogicalThreadContextStack.cs
@@ -32,6 +32,7 @@ public delegate void TwoArgAction<T1, T2>(T1 t1, T2 t2);
/// Implementation of Stack for the <see cref="LogicalThreadContext"/>
/// </summary>
/// <author>Nicko Cadell</author>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public sealed class LogicalThreadContextStack : IFixingRequired
{
/// <summary>
@@ -61,8 +62,8 @@ public sealed class LogicalThreadContextStack : IFixingRequired
/// </remarks>
internal LogicalThreadContextStack(string propertyKey, TwoArgAction<string, LogicalThreadContextStack> registerNew)
{
- this._propertyKey = propertyKey;
- this._registerNew = registerNew;
+ _propertyKey = propertyKey;
+ _registerNew = registerNew;
}
/// <summary>
@@ -92,10 +93,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
/// syntax.
/// </para>
/// </remarks>
- public void Clear()
- {
- _registerNew(_propertyKey, new LogicalThreadContextStack(_propertyKey, _registerNew));
- }
+ public void Clear() => _registerNew(_propertyKey, new LogicalThreadContextStack(_propertyKey, _registerNew));
/// <summary>
/// Removes the top context from this stack.
@@ -111,13 +109,13 @@ public sealed class LogicalThreadContextStack : IFixingRequired
public string? Pop()
{
// copy current stack
- var stack = new Stack<StackFrame>(new Stack<StackFrame>(this._stack));
+ Stack<StackFrame> stack = new(new Stack<StackFrame>(_stack));
string? result = string.Empty;
if (stack.Count > 0)
{
result = stack.Pop().Message;
}
- var ltcs = new LogicalThreadContextStack(_propertyKey, _registerNew) { _stack = stack };
+ LogicalThreadContextStack ltcs = new(_propertyKey, _registerNew) { _stack = stack };
_registerNew(_propertyKey, ltcs);
return result;
}
@@ -148,11 +146,10 @@ public sealed class LogicalThreadContextStack : IFixingRequired
public IDisposable Push(string? message)
{
// do modifications on a copy
- var stack = new Stack<StackFrame>(new Stack<StackFrame>(this._stack));
+ Stack<StackFrame> stack = new(new Stack<StackFrame>(_stack));
stack.Push(new StackFrame(message, (stack.Count > 0) ? stack.Peek() : null));
- LogicalThreadContextStack contextStack = new LogicalThreadContextStack(_propertyKey, _registerNew);
- contextStack._stack = stack;
+ LogicalThreadContextStack contextStack = new(_propertyKey, _registerNew) { _stack = stack };
_registerNew(_propertyKey, contextStack);
return new AutoPopStackFrame(contextStack, stack.Count - 1);
}
@@ -224,7 +221,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
internal StackFrame(string? message, StackFrame? parent)
{
Message = message;
- this._parent = parent;
+ _parent = parent;
if (parent is null)
{
@@ -302,8 +299,8 @@ public sealed class LogicalThreadContextStack : IFixingRequired
/// </remarks>
internal AutoPopStackFrame(LogicalThreadContextStack logicalThreadContextStack, int frameDepth)
{
- this._frameDepth = frameDepth;
- this._logicalThreadContextStack = logicalThreadContextStack;
+ _frameDepth = frameDepth;
+ _logicalThreadContextStack = logicalThreadContextStack;
}
/// <summary>
diff --git a/src/log4net/Util/NativeMethods.cs b/src/log4net/Util/NativeMethods.cs
index 74ea48b8..339a5427 100644
--- a/src/log4net/Util/NativeMethods.cs
+++ b/src/log4net/Util/NativeMethods.cs
@@ -121,7 +121,7 @@ namespace log4net.Util
/// </para>
/// <para>
/// If the function fails, the return value is zero. To get extended error information,
- /// call <see cref="M:Marshal.GetLastWin32Error()" />.
+ /// call <see cref="Marshal.GetLastWin32Error()" />.
/// </para>
/// </returns>
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
diff --git a/src/log4net/Util/NullSecurityContext.cs b/src/log4net/Util/NullSecurityContext.cs
index e5393135..760de9f3 100644
--- a/src/log4net/Util/NullSecurityContext.cs
+++ b/src/log4net/Util/NullSecurityContext.cs
@@ -44,7 +44,7 @@ public sealed class NullSecurityContext : SecurityContext
/// Singleton instance of <see cref="NullSecurityContext"/>
/// </para>
/// </remarks>
- public static readonly NullSecurityContext Instance = new NullSecurityContext();
+ public static readonly NullSecurityContext Instance = new();
/// <summary>
/// Private constructor
diff --git a/src/log4net/Util/OptionConverter.cs b/src/log4net/Util/OptionConverter.cs
index b4b28b52..3e9539cd 100644
--- a/src/log4net/Util/OptionConverter.cs
+++ b/src/log4net/Util/OptionConverter.cs
@@ -142,13 +142,8 @@ public static class OptionConverter
/// </remarks>
public static object? ConvertStringTo(Type target, string txt)
{
- if (target is null)
- {
- throw new ArgumentNullException(nameof(target));
- }
-
// If we want a string we already have the correct type
- if (typeof(string) == target || typeof(object) == target)
+ if (typeof(string) == target.EnsureNotNull() || typeof(object) == target)
{
return txt;
}
@@ -160,32 +155,22 @@ public static class OptionConverter
// Found appropriate converter
return typeConverter.ConvertFrom(txt);
}
- else
+ if (target.IsEnum)
{
- if (target.IsEnum)
- {
- // Target type is an enum.
-
- // Use the Enum.Parse(EnumType, string) method to get the enum value
- return ParseEnum(target, txt, true);
- }
- else
- {
- // We essentially make a guess that to convert from a string
- // to an arbitrary type T there will be a static method defined on type T called Parse
- // that will take an argument of type string. i.e. T.Parse(string)->T we call this
- // method to convert the string to the type required by the property.
- if (target.GetMethod("Parse", [typeof(string)]) is MethodInfo meth)
- {
- // Call the Parse method
- return meth.Invoke(null, BindingFlags.InvokeMethod, null, [txt], CultureInfo.InvariantCulture);
- }
- else
- {
- // No Parse() method found.
- }
- }
+ // Target type is an enum.
+ // Use the Enum.Parse(EnumType, string) method to get the enum value
+ return ParseEnum(target, txt, true);
}
+ // We essentially make a guess that to convert from a string
+ // to an arbitrary type T there will be a static method defined on type T called Parse
+ // that will take an argument of type string. i.e. T.Parse(string)->T we call this
+ // method to convert the string to the type required by the property.
+ if (target.GetMethod("Parse", [typeof(string)]) is MethodInfo meth)
+ {
+ // Call the Parse method
+ return meth.Invoke(null, BindingFlags.InvokeMethod, null, [txt], CultureInfo.InvariantCulture);
+ }
+ // No Parse() method found.
return null;
}
@@ -214,24 +199,13 @@ public static class OptionConverter
}
// Look for a To converter
- if (ConverterRegistry.GetConvertTo(sourceType, targetType) is IConvertTo tcSource)
+ if (ConverterRegistry.GetConvertTo(sourceType, targetType) is IConvertTo tcSource && tcSource.CanConvertTo(targetType))
{
- if (tcSource.CanConvertTo(targetType))
- {
- return true;
- }
+ return true;
}
// Look for a From converter
- if (ConverterRegistry.GetConvertFrom(targetType) is IConvertFrom tcTarget)
- {
- if (tcTarget.CanConvertFrom(sourceType))
- {
- return true;
- }
- }
-
- return false;
+ return ConverterRegistry.GetConvertFrom(targetType) is IConvertFrom tcTarget && tcTarget.CanConvertFrom(sourceType);
}
/// <summary>
@@ -256,21 +230,15 @@ public static class OptionConverter
}
// Look for a TO converter
- if (ConverterRegistry.GetConvertTo(sourceType, targetType) is IConvertTo tcSource)
+ if (ConverterRegistry.GetConvertTo(sourceType, targetType) is IConvertTo tcSource && tcSource.CanConvertTo(targetType))
{
- if (tcSource.CanConvertTo(targetType))
- {
- return tcSource.ConvertTo(sourceInstance, targetType);
- }
+ return tcSource.ConvertTo(sourceInstance, targetType);
}
// Look for a FROM converter
- if (ConverterRegistry.GetConvertFrom(targetType) is IConvertFrom tcTarget)
+ if (ConverterRegistry.GetConvertFrom(targetType) is IConvertFrom tcTarget && tcTarget.CanConvertFrom(sourceType))
{
- if (tcTarget.CanConvertFrom(sourceType))
- {
- return tcTarget.ConvertFrom(sourceInstance);
- }
+ return tcTarget.ConvertFrom(sourceInstance);
}
throw new ArgumentException($"Cannot convert source object [{sourceInstance}] to target type [{targetType.Name}]", nameof(sourceInstance));
@@ -418,10 +386,8 @@ public static class OptionConverter
/// <param name="value">The enum string value.</param>
/// <param name="ignoreCase">If <c>true</c>, ignore case; otherwise, regard case.</param>
/// <returns>An object of type <paramref name="enumType" /> whose value is represented by <paramref name="value" />.</returns>
- private static object ParseEnum(Type enumType, string value, bool ignoreCase)
- {
- return Enum.Parse(enumType, value, ignoreCase);
- }
+ private static object ParseEnum(Type enumType, string value, bool ignoreCase)
+ => Enum.Parse(enumType, value, ignoreCase);
/// <summary>
/// The fully qualified type of the OptionConverter class.
diff --git a/src/log4net/Util/PatternConverter.cs b/src/log4net/Util/PatternConverter.cs
index cb5128f6..d2189eb6 100644
--- a/src/log4net/Util/PatternConverter.cs
+++ b/src/log4net/Util/PatternConverter.cs
@@ -49,8 +49,7 @@ public abstract class PatternConverter
/// </para>
/// </remarks>
protected PatternConverter()
- {
- }
+ { }
/// <summary>
/// Gets the next pattern converter in the chain.
@@ -70,10 +69,10 @@ public abstract class PatternConverter
/// </remarks>
public virtual FormattingInfo FormattingInfo
{
- get { return new FormattingInfo(_min, _max, _leftAlign); }
+ get => new(_min, _max, _leftAlign);
set
{
- _min = value.Min;
+ _min = value.EnsureNotNull().Min;
_max = value.Max;
_leftAlign = value.LeftAlign;
}
@@ -137,6 +136,7 @@ public abstract class PatternConverter
/// </remarks>
public virtual void Format(TextWriter writer, object? state)
{
+ writer.EnsureNotNull();
if (_min < 0 && _max == int.MaxValue)
{
// Formatting options are not in use
@@ -146,9 +146,9 @@ public abstract class PatternConverter
{
string? msg;
int len;
- lock (_formatWriter)
+ lock (_syncRoot)
{
- _formatWriter.Reset(CRenderBufferMaxCapacity, CRenderBufferSize);
+ _formatWriter.Reset(MaxRenderBufferCapacity, DefaultRenderBufferSize);
Convert(_formatWriter, state);
@@ -209,6 +209,7 @@ public abstract class PatternConverter
/// </remarks>
protected static void SpacePad(TextWriter writer, int length)
{
+ writer.EnsureNotNull();
while (length >= 32)
{
writer.Write(_spaces[5]);
@@ -229,17 +230,18 @@ public abstract class PatternConverter
private int _max = int.MaxValue;
private bool _leftAlign;
+ private readonly object _syncRoot = new();
private readonly ReusableStringWriter _formatWriter = new(System.Globalization.CultureInfo.InvariantCulture);
/// <summary>
/// Initial buffer size
/// </summary>
- private const int CRenderBufferSize = 256;
+ private const int DefaultRenderBufferSize = 256;
/// <summary>
/// Maximum buffer size before it is recycled
/// </summary>
- private const int CRenderBufferMaxCapacity = 1024;
+ private const int MaxRenderBufferCapacity = 1024;
/// <summary>
/// Write an dictionary to a <see cref="TextWriter"/>
@@ -261,9 +263,7 @@ public abstract class PatternConverter
/// </para>
/// </remarks>
protected static void WriteDictionary(TextWriter writer, ILoggerRepository? repository, IDictionary value)
- {
- WriteDictionary(writer, repository, value.GetEnumerator());
- }
+ => WriteDictionary(writer, repository, value.EnsureNotNull().GetEnumerator());
/// <summary>
/// Writes a dictionary to a <see cref="TextWriter"/>
@@ -286,8 +286,8 @@ public abstract class PatternConverter
/// </remarks>
protected static void WriteDictionary(TextWriter writer, ILoggerRepository? repository, IDictionaryEnumerator value)
{
- writer.Write("{");
-
+ value.EnsureNotNull();
+ writer.EnsureNotNull().Write("{");
bool first = true;
// Write out all the dictionary key value pairs
@@ -324,6 +324,7 @@ public abstract class PatternConverter
/// </remarks>
protected static void WriteObject(TextWriter writer, ILoggerRepository? repository, object? value)
{
+ writer.EnsureNotNull();
if (repository is not null)
{
repository.RendererMap.FindAndRender(value, writer);
@@ -345,5 +346,6 @@ public abstract class PatternConverter
/// <summary>
///
/// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only")]
public PropertiesDictionary? Properties { get; set; }
}
diff --git a/src/log4net/Util/PatternString.cs b/src/log4net/Util/PatternString.cs
index 1e46e707..1dca01b9 100644
--- a/src/log4net/Util/PatternString.cs
+++ b/src/log4net/Util/PatternString.cs
@@ -81,7 +81,7 @@ namespace log4net.Util;
/// </para>
/// <para>
/// The date format specifier admits the same syntax as the
-/// time pattern string of the <see cref="M:DateTime.ToString(string)"/>.
+/// time pattern string of the <see cref="DateTime.ToString(string)"/>.
/// </para>
/// <para>
/// For better results it is recommended to use the log4net date
@@ -94,7 +94,7 @@ namespace log4net.Util;
/// </para>
/// <para>
/// These dedicated date formatters perform significantly
-/// better than <see cref="M:DateTime.ToString(string)"/>.
+/// better than <see cref="DateTime.ToString(string)"/>.
/// </para>
/// </description>
/// </item>
@@ -216,7 +216,7 @@ namespace log4net.Util;
/// </para>
/// <para>
/// The date format specifier admits the same syntax as the
-/// time pattern string of the <see cref="M:DateTime.ToString(string)"/>.
+/// time pattern string of the <see cref="DateTime.ToString(string)"/>.
/// </para>
/// <para>
/// For better results it is recommended to use the log4net date
@@ -229,7 +229,7 @@ namespace log4net.Util;
/// </para>
/// <para>
/// These dedicated date formatters perform significantly
-/// better than <see cref="M:DateTime.ToString(string)"/>.
+/// better than <see cref="DateTime.ToString(string)"/>.
/// </para>
/// </description>
/// </item>
@@ -244,8 +244,8 @@ namespace log4net.Util;
/// </list>
/// <para>
/// Additional pattern converters may be registered with a specific <see cref="PatternString"/>
-/// instance using <see cref="M:AddConverter(ConverterInfo)"/> or
-/// <see cref="M:AddConverter(string, Type)" />.
+/// instance using <see cref="AddConverter(ConverterInfo)"/> or
+/// <see cref="AddConverter(string, Type)" />.
/// </para>
/// <para>
/// See the <see cref="log4net.Layout.PatternLayout"/> for details on the
@@ -312,6 +312,7 @@ public class PatternString : IOptionHandler
/// Initialize a new instance of <see cref="PatternString"/> with the pattern specified.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors")]
public PatternString(string? pattern)
{
ConversionPattern = pattern;
@@ -442,7 +443,7 @@ public class PatternString : IOptionHandler
/// <remarks>
/// <para>
/// This version of the method is used by the configurator.
- /// Programmatic users should use the alternative <see cref="M:AddConverter(string,Type)"/> method.
+ /// Programmatic users should use the alternative <see cref="AddConverter(string,Type)"/> method.
/// The converter name is case-insensitive.
/// </para>
/// </remarks>
@@ -450,7 +451,7 @@ public class PatternString : IOptionHandler
{
if (!typeof(PatternConverter).IsAssignableFrom(converterInfo.EnsureNotNull().Type))
{
- throw new ArgumentException($"The converter type specified [{converterInfo.Type}] must be a subclass of log4net.Util.PatternConverter", "converterInfo");
+ throw new ArgumentException($"The converter type specified [{converterInfo.Type}] must be a subclass of log4net.Util.PatternConverter", nameof(converterInfo));
}
_instanceRulesRegistry[converterInfo.Name] = converterInfo;
}
@@ -462,7 +463,7 @@ public class PatternString : IOptionHandler
/// <param name="type">the type of the converter</param>
public void AddConverter(string name, Type type)
{
- AddConverter(new ConverterInfo()
+ AddConverter(new()
{
Name = name.EnsureNotNull(),
Type = type.EnsureNotNull()
diff --git a/src/log4net/Util/PatternStringConverters/DatePatternConverter.cs b/src/log4net/Util/PatternStringConverters/DatePatternConverter.cs
index 3d23c5f3..086f124a 100644
--- a/src/log4net/Util/PatternStringConverters/DatePatternConverter.cs
+++ b/src/log4net/Util/PatternStringConverters/DatePatternConverter.cs
@@ -67,7 +67,7 @@ namespace log4net.Util.PatternStringConverters;
/// <description>
/// Any other pattern string uses the <see cref="SimpleDateFormatter"/> formatter.
/// This formatter passes the pattern string to the <see cref="DateTime"/>
-/// <see cref="M:DateTime.ToString(string)"/> method.
+/// <see cref="DateTime.ToString(string)"/> method.
/// For details on valid patterns see
/// <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp">DateTimeFormatInfo Class</a>.
/// </description>
diff --git a/src/log4net/Util/ReadOnlyPropertiesDictionary.cs b/src/log4net/Util/ReadOnlyPropertiesDictionary.cs
index 1efa55f9..125b836c 100644
--- a/src/log4net/Util/ReadOnlyPropertiesDictionary.cs
+++ b/src/log4net/Util/ReadOnlyPropertiesDictionary.cs
@@ -68,7 +68,7 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// </remarks>
public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary)
{
- foreach (KeyValuePair<string, object?> entry in propertiesDictionary)
+ foreach (KeyValuePair<string, object?> entry in propertiesDictionary.EnsureNotNull())
{
InnerHashtable[entry.Key] = entry.Value;
}
@@ -85,9 +85,10 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// with serialized data.
/// </para>
/// </remarks>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter")]
protected ReadOnlyPropertiesDictionary(SerializationInfo info, StreamingContext context)
{
- foreach (var entry in info)
+ foreach (SerializationEntry entry in info.EnsureNotNull())
{
// The keys are stored as Xml encoded names
InnerHashtable[XmlConvert.DecodeName(entry.Name) ?? string.Empty] = entry.Value;
@@ -118,26 +119,20 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="IDictionary{TKey,TValue}.Add(TKey,TValue)"/>.
/// </summary>
- public virtual void Add(string key, object? value)
- {
- throw new NotSupportedException(ReadOnlyMessage);
- }
+ public virtual void Add(string key, object? value)
+ => throw new NotSupportedException(ReadOnlyMessage);
/// <summary>
/// See <see cref="IDictionary{TKey,TValue}.Remove(TKey)"/>.
/// </summary>
- public virtual bool Remove(string key)
- {
- throw new NotSupportedException(ReadOnlyMessage);
- }
+ public virtual bool Remove(string key)
+ => throw new NotSupportedException(ReadOnlyMessage);
/// <summary>
/// See <see cref="IDictionary{TKey,TValue}.TryGetValue(TKey,out TValue)"/>.
/// </summary>
- public bool TryGetValue(string key, out object? value)
- {
- return InnerHashtable.TryGetValue(key, out value);
- }
+ public bool TryGetValue(string key, out object? value)
+ => InnerHashtable.TryGetValue(key, out value);
/// <summary>
/// Gets or sets the value of the property with the specified key.
@@ -174,10 +169,7 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// Test if the dictionary contains a specified key
/// </para>
/// </remarks>
- public bool Contains(string key)
- {
- return InnerHashtable.ContainsKey(key);
- }
+ public bool Contains(string key) => InnerHashtable.ContainsKey(key);
/// <summary>
/// The hashtable used to store the properties
@@ -206,10 +198,11 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, SerializationFormatter = true)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
+ info.EnsureNotNull();
foreach (KeyValuePair<string, object?> entry in InnerHashtable)
{
// If value is serializable then we add it to the list
- var isSerializable = entry.Value?.GetType().IsSerializable ?? false;
+ bool isSerializable = entry.Value?.GetType().IsSerializable ?? false;
if (!isSerializable)
{
continue;
@@ -219,8 +212,7 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
// which are NOT escaped by the Xml Serialization framework.
// This must be a bug in the serialization framework as we cannot be expected
// to know the implementation details of all the possible transport layers.
- var localKeyName = XmlConvert.EncodeLocalName(entry.Key);
- if (localKeyName is not null)
+ if (XmlConvert.EncodeLocalName(entry.Key) is string localKeyName)
{
info.AddValue(localKeyName, entry.Value);
}
@@ -230,27 +222,18 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="IDictionary.GetEnumerator"/>
/// </summary>
- IDictionaryEnumerator IDictionary.GetEnumerator()
- {
- return InnerHashtable.GetEnumerator();
- }
+ IDictionaryEnumerator IDictionary.GetEnumerator() => InnerHashtable.GetEnumerator();
/// <summary>
/// See <see cref="IEnumerable{T}.GetEnumerator"/>
/// </summary>
- IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator()
- {
- return InnerHashtable.GetEnumerator();
- }
+ IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator() => InnerHashtable.GetEnumerator();
/// <summary>
/// See <see cref="IDictionary.Remove"/>
/// </summary>
/// <param name="key"></param>
- void IDictionary.Remove(object key)
- {
- throw new NotSupportedException(ReadOnlyMessage);
- }
+ void IDictionary.Remove(object key) => throw new NotSupportedException(ReadOnlyMessage);
/// <summary>
/// See <see cref="IDictionary.Contains"/>
@@ -267,36 +250,28 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="ICollection{T}.Add(T)"/>.
/// </summary>
- public void Add(KeyValuePair<string, object?> item)
- {
- InnerHashtable.Add(item.Key, item.Value);
- }
+ public void Add(KeyValuePair<string, object?> item) => InnerHashtable.Add(item.Key, item.Value);
/// <summary>
/// Removes all properties from the properties collection
/// </summary>
- public virtual void Clear()
- {
- throw new NotSupportedException(ReadOnlyMessage);
- }
+ public virtual void Clear() => throw new NotSupportedException(ReadOnlyMessage);
/// <summary>
/// See <see cref="ICollection{T}.Contains(T)"/>.
/// </summary>
- public bool Contains(KeyValuePair<string, object?> item)
- {
- return InnerHashtable.TryGetValue(item.Key, out object? v) && item.Value == v;
- }
+ public bool Contains(KeyValuePair<string, object?> item) => InnerHashtable.TryGetValue(item.Key, out object? v) && item.Value == v;
/// <summary>
/// See <see cref="ICollection{T}.CopyTo(T[],int)"/>.
/// </summary>
public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
{
+ array.EnsureNotNull();
int i = arrayIndex;
- foreach (var kvp in InnerHashtable)
+ foreach (var entry in InnerHashtable)
{
- array[i] = kvp;
+ array[i] = entry;
i++;
}
}
@@ -304,18 +279,12 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="ICollection{T}.Remove(T)"/>.
/// </summary>
- public bool Remove(KeyValuePair<string, object?> item)
- {
- return InnerHashtable.Remove(item.Key);
- }
+ public bool Remove(KeyValuePair<string, object?> item) => InnerHashtable.Remove(item.Key);
/// <summary>
/// See <see cref="IDictionary.Add"/>.
/// </summary>
- void IDictionary.Add(object key, object? value)
- {
- throw new NotSupportedException(ReadOnlyMessage);
- }
+ void IDictionary.Add(object key, object? value) => throw new NotSupportedException(ReadOnlyMessage);
/// <summary>
/// See <see cref="IDictionary.IsReadOnly"/>.
@@ -342,6 +311,7 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="IDictionary{TKey,TValue}.Keys"/>.
/// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721:Property names should not match get methods")]
public ICollection<string> Keys => InnerHashtable.Keys;
/// <summary>
@@ -367,10 +337,7 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="ICollection.CopyTo"/>
/// </summary>
- void ICollection.CopyTo(Array array, int index)
- {
- ((ICollection)InnerHashtable).CopyTo(array, index);
- }
+ void ICollection.CopyTo(Array array, int index) => ((ICollection)InnerHashtable).CopyTo(array, index);
/// <summary>
/// See <see cref="ICollection.IsSynchronized"/>
@@ -395,8 +362,5 @@ public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, I
/// <summary>
/// See <see cref="IEnumerable.GetEnumerator"/>
/// </summary>
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)InnerHashtable).GetEnumerator();
- }
+ IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)InnerHashtable).GetEnumerator();
}
diff --git a/src/log4net/Util/SystemInfo.cs b/src/log4net/Util/SystemInfo.cs
index 5b334039..6c0f05b7 100644
--- a/src/log4net/Util/SystemInfo.cs
+++ b/src/log4net/Util/SystemInfo.cs
@@ -406,7 +406,7 @@ public static class SystemInfo
/// <para>
/// If the type name is fully qualified, i.e. if contains an assembly name in
/// the type name, the type will be loaded from the system using
- /// <see cref="M:Type.GetType(string,bool)"/>.
+ /// <see cref="Type.GetType(string,bool)"/>.
/// </para>
/// <para>
/// If the type name is not fully qualified, it will be loaded from the assembly
@@ -430,7 +430,7 @@ public static class SystemInfo
/// <para>
/// If the type name is fully qualified, i.e. if contains an assembly name in
/// the type name, the type will be loaded from the system using
- /// <see cref="M:Type.GetType(string,bool)"/>.
+ /// <see cref="Type.GetType(string,bool)"/>.
/// </para>
/// <para>
/// If the type name is not fully qualified it will be loaded from the
@@ -455,7 +455,7 @@ public static class SystemInfo
/// <para>
/// If the type name is fully qualified, i.e. if contains an assembly name in
/// the type name, the type will be loaded from the system using
- /// <see cref="M:Type.GetType(string,bool)"/>.
+ /// <see cref="Type.GetType(string,bool)"/>.
/// </para>
/// <para>
/// If the type name is not fully qualified it will be loaded from the specified
@@ -534,14 +534,14 @@ public static class SystemInfo
/// of the argument.
/// </returns>
public static ArgumentOutOfRangeException CreateArgumentOutOfRangeException(string parameterName, object actualValue, string message)
- => new ArgumentOutOfRangeException(parameterName, actualValue, message);
+ => new(parameterName, actualValue, message);
/// <summary>
/// Creates a <see cref="NotSupportedException"/> for read-only collection modification calls.
/// </summary>
/// <returns>The NotSupportedException object</returns>
public static NotSupportedException CreateReadOnlyCollectionNotModifiableException()
- => new NotSupportedException("This is a Read Only Collection and can not be modified");
+ => new("This is a Read Only Collection and can not be modified");
/// <summary>
/// Parse a string into an <see cref="int"/> value
diff --git a/src/log4net/Util/ThreadContextProperties.cs b/src/log4net/Util/ThreadContextProperties.cs
index ff2373de..6760cf07 100644
--- a/src/log4net/Util/ThreadContextProperties.cs
+++ b/src/log4net/Util/ThreadContextProperties.cs
@@ -31,6 +31,7 @@ namespace log4net.Util;
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")]
public sealed class ThreadContextProperties : ContextPropertiesBase
{
/// <summary>
@@ -48,8 +49,7 @@ public sealed class ThreadContextProperties : ContextPropertiesBase
/// </para>
/// </remarks>
internal ThreadContextProperties()
- {
- }
+ { }
/// <summary>
/// Gets or sets the value of a property
diff --git a/src/log4net/Util/ThreadContextStack.cs b/src/log4net/Util/ThreadContextStack.cs
index e39bf7fa..6c088916 100644
--- a/src/log4net/Util/ThreadContextStack.cs
+++ b/src/log4net/Util/ThreadContextStack.cs
@@ -34,6 +34,7 @@ namespace log4net.Util;
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public sealed class ThreadContextStack : IFixingRequired
{
/// <summary>
@@ -50,8 +51,7 @@ public sealed class ThreadContextStack : IFixingRequired
/// </para>
/// </remarks>
internal ThreadContextStack()
- {
- }
+ { }
/// <summary>
/// The number of messages in the stack
@@ -228,7 +228,7 @@ public sealed class ThreadContextStack : IFixingRequired
internal StackFrame(string? message, StackFrame? parent)
{
Message = message;
- this._parent = parent;
+ _parent = parent;
if (parent is null)
{
@@ -286,8 +286,8 @@ public sealed class ThreadContextStack : IFixingRequired
/// <param name="frameDepth">The depth to return the stack to when this object is disposed.</param>
internal AutoPopStackFrame(Stack<StackFrame> frameStack, int frameDepth)
{
- this._frameStack = frameStack;
- this._frameDepth = frameDepth;
+ _frameStack = frameStack;
+ _frameDepth = frameDepth;
}
/// <summary>
diff --git a/src/log4net/Util/Transform.cs b/src/log4net/Util/Transform.cs
index ea1a795f..6ff80086 100644
--- a/src/log4net/Util/Transform.cs
+++ b/src/log4net/Util/Transform.cs
@@ -48,6 +48,7 @@ public static class Transform
/// </remarks>
public static void WriteEscapedXmlString(XmlWriter writer, string textData, string invalidCharReplacement)
{
+ writer.EnsureNotNull();
string stringData = MaskXmlInvalidCharacters(textData, invalidCharReplacement);
// Write either escaped text or CDATA sections
@@ -113,10 +114,8 @@ public static class Transform
/// with the mask string specified.
/// </para>
/// </remarks>
- public static string MaskXmlInvalidCharacters(string textData, string mask)
- {
- return _invalidchars.Replace(textData, mask);
- }
+ public static string MaskXmlInvalidCharacters(string textData, string mask)
+ => _invalidchars.Replace(textData, mask);
/// <summary>
/// Count the number of times that the substring occurs in the text
diff --git a/src/log4net/Util/TypeConverters/BooleanConverter.cs b/src/log4net/Util/TypeConverters/BooleanConverter.cs
index a63bba78..ae1dba2b 100644
--- a/src/log4net/Util/TypeConverters/BooleanConverter.cs
+++ b/src/log4net/Util/TypeConverters/BooleanConverter.cs
@@ -46,7 +46,7 @@ internal sealed class BooleanConverter : IConvertFrom
/// </returns>
public bool CanConvertFrom(Type sourceType)
{
- return (sourceType == typeof(string));
+ return sourceType == typeof(string);
}
/// <summary>
diff --git a/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs b/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs
index 300d7c0e..d87ec043 100644
--- a/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs
+++ b/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs
@@ -35,6 +35,7 @@ namespace log4net.Util.TypeConverters;
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
[Log4NetSerializable]
+[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1058:Types should not extend certain base types")]
public class ConversionNotSupportedException : ApplicationException
{
/// <summary>
@@ -46,8 +47,7 @@ public class ConversionNotSupportedException : ApplicationException
/// </para>
/// </remarks>
public ConversionNotSupportedException()
- {
- }
+ { }
/// <summary>
/// Constructor
@@ -59,9 +59,9 @@ public class ConversionNotSupportedException : ApplicationException
/// with the specified message.
/// </para>
/// </remarks>
- public ConversionNotSupportedException(string message) : base(message)
- {
- }
+ public ConversionNotSupportedException(string message)
+ : base(message)
+ { }
/// <summary>
/// Constructor
@@ -74,9 +74,9 @@ public class ConversionNotSupportedException : ApplicationException
/// with the specified message and inner exception.
/// </para>
/// </remarks>
- public ConversionNotSupportedException(string message, Exception? innerException) : base(message, innerException)
- {
- }
+ public ConversionNotSupportedException(string message, Exception? innerException)
+ : base(message, innerException)
+ { }
/// <summary>
/// Serialization constructor
@@ -89,9 +89,9 @@ public class ConversionNotSupportedException : ApplicationException
/// with serialized data.
/// </para>
/// </remarks>
- protected ConversionNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
+ protected ConversionNotSupportedException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ { }
/// <summary>
/// Creates a new instance of the <see cref="ConversionNotSupportedException" /> class.
@@ -105,9 +105,7 @@ public class ConversionNotSupportedException : ApplicationException
/// </para>
/// </remarks>
public static ConversionNotSupportedException Create(Type destinationType, object sourceValue)
- {
- return Create(destinationType, sourceValue, null);
- }
+ => Create(destinationType, sourceValue, null);
/// <summary>
/// Creates a new instance of the <see cref="ConversionNotSupportedException" /> class.
@@ -127,9 +125,6 @@ public class ConversionNotSupportedException : ApplicationException
{
return new ConversionNotSupportedException($"Cannot convert value [null] to type [{destinationType}]", innerException);
}
- else
- {
- return new ConversionNotSupportedException($"Cannot convert from type [{sourceValue.GetType()}] value [{sourceValue}] to type [{destinationType}]", innerException);
- }
+ return new ConversionNotSupportedException($"Cannot convert from type [{sourceValue.GetType()}] value [{sourceValue}] to type [{destinationType}]", innerException);
}
}
diff --git a/src/log4net/Util/TypeConverters/ConverterRegistry.cs b/src/log4net/Util/TypeConverters/ConverterRegistry.cs
index c8a19458..82eb0140 100644
--- a/src/log4net/Util/TypeConverters/ConverterRegistry.cs
+++ b/src/log4net/Util/TypeConverters/ConverterRegistry.cs
@@ -30,8 +30,8 @@ namespace log4net.Util.TypeConverters;
/// Maintains a registry of type converters used to convert between types.
/// </para>
/// <para>
-/// Use the <see cref="M:AddConverter(Type, object)"/> and
-/// <see cref="M:AddConverter(Type, Type)"/> methods to register new converters.
+/// Use the <see cref="AddConverter(Type, object)"/> and
+/// <see cref="AddConverter(Type, Type)"/> methods to register new converters.
/// The <see cref="GetConvertTo"/> and <see cref="GetConvertFrom"/> methods
/// lookup appropriate converters to use.
/// </para>
diff --git a/src/log4net/Util/TypeConverters/EncodingConverter.cs b/src/log4net/Util/TypeConverters/EncodingConverter.cs
index c7ddcf54..58d60e12 100644
--- a/src/log4net/Util/TypeConverters/EncodingConverter.cs
+++ b/src/log4net/Util/TypeConverters/EncodingConverter.cs
@@ -42,7 +42,7 @@ internal sealed class EncodingConverter : IConvertFrom
/// </returns>
public bool CanConvertFrom(Type sourceType)
{
- return (sourceType == typeof(string));
+ return sourceType == typeof(string);
}
/// <summary>
@@ -52,7 +52,7 @@ internal sealed class EncodingConverter : IConvertFrom
/// <returns>the encoding</returns>
/// <remarks>
/// <para>
- /// Uses the <see cref="M:Encoding.GetEncoding(string)"/> method to
+ /// Uses the <see cref="Encoding.GetEncoding(string)"/> method to
/// convert the <see cref="string"/> argument to an <see cref="Encoding"/>.
/// </para>
/// </remarks>
diff --git a/src/log4net/Util/TypeConverters/IPAddressConverter.cs b/src/log4net/Util/TypeConverters/IPAddressConverter.cs
index 85a5ed4f..1c98ed4b 100644
--- a/src/log4net/Util/TypeConverters/IPAddressConverter.cs
+++ b/src/log4net/Util/TypeConverters/IPAddressConverter.cs
@@ -49,7 +49,7 @@ internal sealed class IpAddressConverter : IConvertFrom
/// </remarks>
public bool CanConvertFrom(Type sourceType)
{
- return (sourceType == typeof(string));
+ return sourceType == typeof(string);
}
/// <summary>
diff --git a/src/log4net/Util/TypeConverters/PatternLayoutConverter.cs b/src/log4net/Util/TypeConverters/PatternLayoutConverter.cs
index c9e1959f..1bf3a72e 100644
--- a/src/log4net/Util/TypeConverters/PatternLayoutConverter.cs
+++ b/src/log4net/Util/TypeConverters/PatternLayoutConverter.cs
@@ -46,7 +46,7 @@ internal sealed class PatternLayoutConverter : IConvertFrom
/// </returns>
public bool CanConvertFrom(System.Type sourceType)
{
- return (sourceType == typeof(string));
+ return sourceType == typeof(string);
}
/// <summary>
diff --git a/src/log4net/Util/TypeConverters/PatternStringConverter.cs b/src/log4net/Util/TypeConverters/PatternStringConverter.cs
index 0e289842..d02b406e 100644
--- a/src/log4net/Util/TypeConverters/PatternStringConverter.cs
+++ b/src/log4net/Util/TypeConverters/PatternStringConverter.cs
@@ -53,7 +53,7 @@ internal sealed class PatternStringConverter : IConvertTo, IConvertFrom
/// </remarks>
public bool CanConvertTo(Type targetType)
{
- return (typeof(string).IsAssignableFrom(targetType));
+ return typeof(string).IsAssignableFrom(targetType);
}
/// <summary>
@@ -64,7 +64,7 @@ internal sealed class PatternStringConverter : IConvertTo, IConvertFrom
/// <returns>the converted object</returns>
/// <remarks>
/// <para>
- /// Uses the <see cref="M:PatternString.Format()"/> method to convert the
+ /// Uses the <see cref="PatternString.Format()"/> method to convert the
/// <see cref="PatternString"/> argument to a <see cref="string"/>.
/// </para>
/// </remarks>
diff --git a/src/log4net/Util/TypeConverters/TypeConverter.cs b/src/log4net/Util/TypeConverters/TypeConverter.cs
index 37373796..a744a03a 100644
--- a/src/log4net/Util/TypeConverters/TypeConverter.cs
+++ b/src/log4net/Util/TypeConverters/TypeConverter.cs
@@ -47,7 +47,7 @@ internal sealed class TypeConverter : IConvertFrom
/// <returns>the Type</returns>
/// <remarks>
/// <para>
- /// Uses the <see cref="M:Type.GetType(string,bool)"/> method to convert the
+ /// Uses the <see cref="Type.GetType(string,bool)"/> method to convert the
/// <see cref="string"/> argument to a <see cref="Type"/>.
/// Additional effort is made to locate partially specified types
/// by searching the loaded assemblies.
diff --git a/src/log4net/Util/TypeConverters/TypeConverterAttribute.cs b/src/log4net/Util/TypeConverters/TypeConverterAttribute.cs
index 1e3a9570..42860a0f 100644
--- a/src/log4net/Util/TypeConverters/TypeConverterAttribute.cs
+++ b/src/log4net/Util/TypeConverters/TypeConverterAttribute.cs
@@ -50,10 +50,8 @@ public sealed class TypeConverterAttribute : Attribute
/// or the <see cref="IConvertTo"/> interfaces.
/// </para>
/// </remarks>
- public TypeConverterAttribute(string typeName)
- {
- ConverterTypeName = typeName;
- }
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
+ public TypeConverterAttribute(string typeName) => ConverterTypeName = typeName;
/// <summary>
/// Creates a new type converter attribute for the specified type
@@ -65,10 +63,9 @@ public sealed class TypeConverterAttribute : Attribute
/// or the <see cref="IConvertTo"/> interfaces.
/// </para>
/// </remarks>
- public TypeConverterAttribute(Type converterType)
- {
- ConverterTypeName = converterType.AssemblyQualifiedName!;
- }
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")]
+ public TypeConverterAttribute(Type converterType)
+ => ConverterTypeName = converterType.EnsureNotNull().AssemblyQualifiedName!;
/// <summary>
/// The string type name of the type converter
diff --git a/src/log4net/Util/WindowsSecurityContext.cs b/src/log4net/Util/WindowsSecurityContext.cs
index 1c24d1e3..9a00c318 100644
--- a/src/log4net/Util/WindowsSecurityContext.cs
+++ b/src/log4net/Util/WindowsSecurityContext.cs
@@ -171,20 +171,7 @@ public class WindowsSecurityContext : Core.SecurityContext, IOptionHandler
{
if (Credentials == ImpersonationMode.User)
{
- if (UserName is null)
- {
- throw new ArgumentNullException(nameof(UserName));
- }
- if (DomainName is null)
- {
- throw new ArgumentNullException(nameof(DomainName));
- }
- if (_password is null)
- {
- throw new ArgumentNullException(nameof(Password));
- }
-
- _identity = LogonUser(UserName, DomainName, _password);
+ _identity = LogonUser(UserName.EnsureNotNull(), DomainName.EnsureNotNull(), _password.EnsureNotNull());
}
}
@@ -278,27 +265,19 @@ public class WindowsSecurityContext : Core.SecurityContext, IOptionHandler
/// <summary>
/// Adds <see cref="IDisposable"/> to <see cref="WindowsImpersonationContext"/>
/// </summary>
+ /// <param name="impersonationContext">the impersonation context being wrapped</param>
/// <remarks>
/// <para>
/// Helper class to expose the <see cref="WindowsImpersonationContext"/>
/// through the <see cref="IDisposable"/> interface.
/// </para>
/// </remarks>
- private sealed class DisposableImpersonationContext : IDisposable
+ private sealed class DisposableImpersonationContext(WindowsImpersonationContext impersonationContext) : IDisposable
{
- private readonly WindowsImpersonationContext _impersonationContext;
-
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="impersonationContext">the impersonation context being wrapped</param>
- public DisposableImpersonationContext(WindowsImpersonationContext impersonationContext)
- => _impersonationContext = impersonationContext;
-
/// <summary>
/// Revert the impersonation
/// </summary>
- public void Dispose() => _impersonationContext.Undo();
+ public void Dispose() => impersonationContext.Undo();
}
}
#endif // NET462_OR_GREATER
\ No newline at end of file