Skip to content

Commit 5df6b49

Browse files
committed
add to-microsoft-logger-factory extension for logger-runtime
1 parent 20cb879 commit 5df6b49

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/Falko.ZeroLogger.Microsoft.Logging/Factories/MicrosoftLoggerFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace System.Logging.Factories;
55

6-
public sealed class MicrosoftLoggerFactory : IMicrosoftLoggerFactory
6+
internal sealed class MicrosoftLoggerFactory : IMicrosoftLoggerFactory
77
{
88
private readonly ConcurrentDictionary<string, IMicrosoftLogger> _loggers = new(StringComparer.Ordinal);
99

@@ -33,6 +33,6 @@ public void AddProvider(IMicrosoftLoggerProvider provider) { }
3333

3434
public void Dispose()
3535
{
36-
_loggerRuntime.Dispose();
36+
if (_disposeLoggerRuntime) _loggerRuntime.Dispose();
3737
}
3838
}

Sources/Falko.ZeroLogger.Microsoft.Logging/Runtimes/LoggerRuntimeExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Logging.Factories;
12
using System.Logging.Providers;
23

34
namespace System.Logging.Runtimes;
@@ -15,4 +16,16 @@ public static IMicrosoftLoggerProvider ToMicrosoftLoggerProvider
1516

1617
return new MicrosoftLoggerProvider(loggerRuntime, forceDispose);
1718
}
19+
20+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
21+
public static IMicrosoftLoggerFactory ToMicrosoftLoggerFactory
22+
(
23+
this LoggerRuntime loggerRuntime,
24+
bool forceDispose = true
25+
)
26+
{
27+
ArgumentNullException.ThrowIfNull(loggerRuntime);
28+
29+
return new MicrosoftLoggerFactory(loggerRuntime, forceDispose);
30+
}
1831
}

0 commit comments

Comments
 (0)