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/09/18 21:14:07 UTC
(logging-log4net) branch Feature/183-fix-pattern-string-for-filename updated: a converter can implement IConvertTo AND IConvertFrom (fixes #183)
This is an automated email from the ASF dual-hosted git repository.
freeandnil pushed a commit to branch Feature/183-fix-pattern-string-for-filename
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/Feature/183-fix-pattern-string-for-filename by this push:
new ad9e5351 a converter can implement IConvertTo AND IConvertFrom (fixes #183)
ad9e5351 is described below
commit ad9e5351f62181e20fca2b403e065aab1a8404dd
Author: Jan Friedrich <fr...@apache.org>
AuthorDate: Wed Sep 18 23:13:31 2024 +0200
a converter can implement IConvertTo AND IConvertFrom (fixes #183)
---
src/log4net.Tests/Appender/FileAppenderTest.cs | 2 -
.../Hierarchy/XmlHierarchyConfigurator.cs | 3 ++
.../Util/TypeConverters/ConverterRegistry.cs | 55 ++++++----------------
src/site/xdoc/release/release-notes.xml | 3 +-
4 files changed, 19 insertions(+), 44 deletions(-)
diff --git a/src/log4net.Tests/Appender/FileAppenderTest.cs b/src/log4net.Tests/Appender/FileAppenderTest.cs
index 709aa5ee..58bcf5c4 100644
--- a/src/log4net.Tests/Appender/FileAppenderTest.cs
+++ b/src/log4net.Tests/Appender/FileAppenderTest.cs
@@ -92,8 +92,6 @@ public sealed class FileAppenderTest
""");
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
- ILog log = LogManager.GetLogger(rep.Name, "GeneralFileAppender");
- log.Info("Message");
}
finally
{
diff --git a/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs b/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
index 06834069..895d10d7 100644
--- a/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
+++ b/src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs
@@ -556,6 +556,9 @@ namespace log4net.Repository.Hierarchy
name = element.LocalName;
}
+ if (name == "file")
+ { }
+
// Look for the property on the target object
Type targetType = target.GetType();
Type? propertyType = null;
diff --git a/src/log4net/Util/TypeConverters/ConverterRegistry.cs b/src/log4net/Util/TypeConverters/ConverterRegistry.cs
index fb0b4cad..5837db82 100644
--- a/src/log4net/Util/TypeConverters/ConverterRegistry.cs
+++ b/src/log4net/Util/TypeConverters/ConverterRegistry.cs
@@ -27,8 +27,7 @@ namespace log4net.Util.TypeConverters
/// </summary>
/// <remarks>
/// <para>
- /// Maintains a registry of type converters used to convert between
- /// types.
+ /// Maintains a registry of type converters used to convert between types.
/// </para>
/// <para>
/// Use the <see cref="M:AddConverter(Type, object)"/> and
@@ -44,13 +43,8 @@ namespace log4net.Util.TypeConverters
public static class ConverterRegistry
{
/// <summary>
- /// Static constructor.
+ /// This class constructor adds the intrinsic type converters
/// </summary>
- /// <remarks>
- /// <para>
- /// This constructor defines the intrinsic type converters.
- /// </para>
- /// </remarks>
static ConverterRegistry()
{
// Add predefined converters here
@@ -67,23 +61,19 @@ namespace log4net.Util.TypeConverters
/// </summary>
/// <param name="destinationType">The type being converted to.</param>
/// <param name="converter">The type converter to use to convert to the destination type.</param>
- /// <remarks>
- /// <para>
- /// Adds a converter instance for a specific type.
- /// </para>
- /// </remarks>
public static void AddConverter(Type? destinationType, object? converter)
{
- if (destinationType is not null && converter is not null)
+ if (destinationType is null || converter is null)
{
- if (converter is IConvertTo convertTo)
- {
- s_type2ConvertTo[destinationType] = convertTo;
- }
- else if (converter is IConvertFrom convertFrom)
- {
- s_type2ConvertFrom[destinationType] = convertFrom;
- }
+ return;
+ }
+ if (converter is IConvertTo convertTo)
+ {
+ s_type2ConvertTo[destinationType] = convertTo;
+ }
+ if (converter is IConvertFrom convertFrom)
+ {
+ s_type2ConvertFrom[destinationType] = convertFrom;
}
}
@@ -92,15 +82,8 @@ namespace log4net.Util.TypeConverters
/// </summary>
/// <param name="destinationType">The type being converted to.</param>
/// <param name="converterType">The type of the type converter to use to convert to the destination type.</param>
- /// <remarks>
- /// <para>
- /// Adds a converter <see cref="Type"/> for a specific type.
- /// </para>
- /// </remarks>
public static void AddConverter(Type destinationType, Type converterType)
- {
- AddConverter(destinationType, CreateConverterInstance(converterType));
- }
+ => AddConverter(destinationType, CreateConverterInstance(converterType));
/// <summary>
/// Gets the type converter to use to convert values to the destination type.
@@ -111,11 +94,6 @@ namespace log4net.Util.TypeConverters
/// The type converter instance to use for type conversions or <c>null</c>
/// if no type converter is found.
/// </returns>
- /// <remarks>
- /// <para>
- /// Gets the type converter to use to convert values to the destination type.
- /// </para>
- /// </remarks>
public static IConvertTo? GetConvertTo(Type sourceType, Type destinationType)
{
// TODO: Support inheriting type converters.
@@ -146,11 +124,6 @@ namespace log4net.Util.TypeConverters
/// The type converter instance to use for type conversions or <c>null</c>
/// if no type converter is found.
/// </returns>
- /// <remarks>
- /// <para>
- /// Gets the type converter to use to convert values to the destination type.
- /// </para>
- /// </remarks>
public static IConvertFrom? GetConvertFrom(Type destinationType)
{
// TODO: Support inheriting type converters.
@@ -248,4 +221,4 @@ namespace log4net.Util.TypeConverters
private static readonly ConcurrentDictionary<Type, IConvertTo> s_type2ConvertTo = new();
private static readonly ConcurrentDictionary<Type, IConvertFrom> s_type2ConvertFrom = new();
}
-}
+}
\ No newline at end of file
diff --git a/src/site/xdoc/release/release-notes.xml b/src/site/xdoc/release/release-notes.xml
index 180affb4..2abc2ef1 100644
--- a/src/site/xdoc/release/release-notes.xml
+++ b/src/site/xdoc/release/release-notes.xml
@@ -28,7 +28,8 @@ limitations under the License.
<section id="a3.0.1-bug" name="Bug fixes">
<ul>
<li>
- <a href="https://github.com/apache/logging-log4net/issues/tbd">tbd</a> (by tbd)
+ <a href="https://github.com/apache/logging-log4net/issues/183">Unable to set property [file] on object [log4net.Appender.FileAppender]</a>
+ (reported by @sc-mk fixed by @FreeAndNil in https://github.com/apache/logging-log4net/pull/176)
</li>
</ul>
</section><section id="a3.0.1-enhancements" name="Enhancements">