Skip to content

Commit 13d4e6d

Browse files
committed
a converter can implement IConvertTo AND IConvertFrom (fixes #183)
1 parent 8d7b03b commit 13d4e6d

File tree

4 files changed

+17
-45
lines changed

4 files changed

+17
-45
lines changed

scripts/build-preview.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dotnet build -c Release '-p:GeneratePackages=true;PackageVersion=3.0.1-preview.1' $PSScriptRoot/../src/log4net/log4net.csproj
1+
dotnet build -c Release '-p:GeneratePackages=true;PackageVersion=3.0.1-preview.2' $PSScriptRoot/../src/log4net/log4net.csproj

src/log4net.Tests/Appender/FileAppenderTest.cs

-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public void FilenameWithPatternStringTest()
9292
""");
9393
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
9494
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
95-
ILog log = LogManager.GetLogger(rep.Name, "GeneralFileAppender");
96-
log.Info("Message");
9795
}
9896
finally
9997
{

src/log4net/Util/TypeConverters/ConverterRegistry.cs

+14-41
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ namespace log4net.Util.TypeConverters
2727
/// </summary>
2828
/// <remarks>
2929
/// <para>
30-
/// Maintains a registry of type converters used to convert between
31-
/// types.
30+
/// Maintains a registry of type converters used to convert between types.
3231
/// </para>
3332
/// <para>
3433
/// Use the <see cref="M:AddConverter(Type, object)"/> and
@@ -44,13 +43,8 @@ namespace log4net.Util.TypeConverters
4443
public static class ConverterRegistry
4544
{
4645
/// <summary>
47-
/// Static constructor.
46+
/// This class constructor adds the intrinsic type converters
4847
/// </summary>
49-
/// <remarks>
50-
/// <para>
51-
/// This constructor defines the intrinsic type converters.
52-
/// </para>
53-
/// </remarks>
5448
static ConverterRegistry()
5549
{
5650
// Add predefined converters here
@@ -67,23 +61,19 @@ static ConverterRegistry()
6761
/// </summary>
6862
/// <param name="destinationType">The type being converted to.</param>
6963
/// <param name="converter">The type converter to use to convert to the destination type.</param>
70-
/// <remarks>
71-
/// <para>
72-
/// Adds a converter instance for a specific type.
73-
/// </para>
74-
/// </remarks>
7564
public static void AddConverter(Type? destinationType, object? converter)
7665
{
77-
if (destinationType is not null && converter is not null)
66+
if (destinationType is null || converter is null)
7867
{
79-
if (converter is IConvertTo convertTo)
80-
{
81-
s_type2ConvertTo[destinationType] = convertTo;
82-
}
83-
else if (converter is IConvertFrom convertFrom)
84-
{
85-
s_type2ConvertFrom[destinationType] = convertFrom;
86-
}
68+
return;
69+
}
70+
if (converter is IConvertTo convertTo)
71+
{
72+
s_type2ConvertTo[destinationType] = convertTo;
73+
}
74+
if (converter is IConvertFrom convertFrom)
75+
{
76+
s_type2ConvertFrom[destinationType] = convertFrom;
8777
}
8878
}
8979

@@ -92,15 +82,8 @@ public static void AddConverter(Type? destinationType, object? converter)
9282
/// </summary>
9383
/// <param name="destinationType">The type being converted to.</param>
9484
/// <param name="converterType">The type of the type converter to use to convert to the destination type.</param>
95-
/// <remarks>
96-
/// <para>
97-
/// Adds a converter <see cref="Type"/> for a specific type.
98-
/// </para>
99-
/// </remarks>
10085
public static void AddConverter(Type destinationType, Type converterType)
101-
{
102-
AddConverter(destinationType, CreateConverterInstance(converterType));
103-
}
86+
=> AddConverter(destinationType, CreateConverterInstance(converterType));
10487

10588
/// <summary>
10689
/// Gets the type converter to use to convert values to the destination type.
@@ -111,11 +94,6 @@ public static void AddConverter(Type destinationType, Type converterType)
11194
/// The type converter instance to use for type conversions or <c>null</c>
11295
/// if no type converter is found.
11396
/// </returns>
114-
/// <remarks>
115-
/// <para>
116-
/// Gets the type converter to use to convert values to the destination type.
117-
/// </para>
118-
/// </remarks>
11997
public static IConvertTo? GetConvertTo(Type sourceType, Type destinationType)
12098
{
12199
// TODO: Support inheriting type converters.
@@ -146,11 +124,6 @@ public static void AddConverter(Type destinationType, Type converterType)
146124
/// The type converter instance to use for type conversions or <c>null</c>
147125
/// if no type converter is found.
148126
/// </returns>
149-
/// <remarks>
150-
/// <para>
151-
/// Gets the type converter to use to convert values to the destination type.
152-
/// </para>
153-
/// </remarks>
154127
public static IConvertFrom? GetConvertFrom(Type destinationType)
155128
{
156129
// TODO: Support inheriting type converters.
@@ -248,4 +221,4 @@ public static void AddConverter(Type destinationType, Type converterType)
248221
private static readonly ConcurrentDictionary<Type, IConvertTo> s_type2ConvertTo = new();
249222
private static readonly ConcurrentDictionary<Type, IConvertFrom> s_type2ConvertFrom = new();
250223
}
251-
}
224+
}

src/site/xdoc/release/release-notes.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ limitations under the License.
2828
<section id="a3.0.1-bug" name="Bug fixes">
2929
<ul>
3030
<li>
31-
<a href="https://github.com/apache/logging-log4net/issues/tbd">tbd</a> (by tbd)
31+
<a href="https://github.com/apache/logging-log4net/issues/183">Unable to set property [file] on object [log4net.Appender.FileAppender]</a>
32+
(reported by @sc-mk fixed by @FreeAndNil in https://github.com/apache/logging-log4net/pull/184)
3233
</li>
3334
</ul>
3435
</section><section id="a3.0.1-enhancements" name="Enhancements">

0 commit comments

Comments
 (0)