Skip to content

Commit b412cf9

Browse files
committed
Remove unused ILoggerT, implement IDisposable pattern for NullLoggerFactory
1 parent f157faa commit b412cf9

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

Ical.Net/Logging/ILoggerT.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

Ical.Net/Logging/Internal/NullLoggerFactory.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
// Licensed under the MIT license.
44
//
55

6+
using System;
7+
68
namespace Ical.Net.Logging.Internal;
79

810
/// <summary>
911
/// Provides a no-operation implementation of <see cref="ILoggerFactory"/> that produces <see cref="NullLogger"/>
1012
/// instances. This factory is intended for scenarios where logging is not required or should be disabled.
1113
/// </summary>
12-
internal class NullLoggerFactory : ILoggerFactory
14+
internal sealed class NullLoggerFactory : ILoggerFactory
1315
{
16+
private bool _disposed;
17+
1418
/// <summary>
1519
/// Provides a singleton instance of a <see cref="NullLoggerFactory"/> that produces no-op loggers.
1620
/// </summary>
@@ -25,9 +29,22 @@ private NullLoggerFactory() { }
2529
/// <returns>A <see cref="NullLogger.Instance"/></returns>
2630
public ILogger CreateLogger(string categoryName) => NullLogger.Instance;
2731

32+
private void Dispose(bool _) //NOSONAR
33+
{
34+
if (_disposed) return;
35+
// No resources to release, implement IDisposable pattern for consistency
36+
_disposed = true;
37+
}
38+
2839
/// <inheritdoc/>
2940
public void Dispose()
3041
{
31-
// no-op
42+
Dispose(true);
43+
GC.SuppressFinalize(this);
44+
}
45+
46+
~NullLoggerFactory()
47+
{
48+
Dispose(false);
3249
}
3350
}

Ical.Net/Logging/LoggingProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ internal static ILogger CreateLogger(string categoryName)
5353
=> (_loggerFactory.Value ?? NullLoggerFactory.Instance).CreateLogger(categoryName);
5454

5555
/// <summary>
56-
/// Gets an <see cref="ILogger{T}"/> instance for the specified type.
56+
/// Gets an <see cref="ILogger"/> instance for the specified type.
5757
/// The category name will be the full name of the type T.
5858
/// </summary>
5959
/// <typeparam name="T">The type for which to create the logger.</typeparam>
60-
/// <returns>An <see cref="ILogger{T}"/> instance.</returns>
60+
/// <returns>An <see cref="ILogger"/> instance.</returns>
6161
internal static ILogger CreateLogger<T>()
6262
=> new Logger<T>(_loggerFactory.Value ?? NullLoggerFactory.Instance);
6363

0 commit comments

Comments
 (0)