Skip to content

Commit 0591df3

Browse files
jamesharlingJames Harling
and
James Harling
authored
Improve reliability of configuration reload (#5)
* Fix config reload loop * Tidy up options reload logic * Refactoring Co-authored-by: James Harling <[email protected]>
1 parent 9f93098 commit 0591df3

File tree

4 files changed

+4
-26
lines changed

4 files changed

+4
-26
lines changed

src/Runpath.Extensions.Logging.AzureEventHubs/AzureEventHubsLogger.cs

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ internal AzureEventHubsLogger(string name, IAzureEventHubsLoggerFormatter logger
1818

1919
internal IExternalScopeProvider ScopeProvider { get; set; }
2020

21-
internal AzureEventHubsLoggerOptions Options { get; set; }
22-
2321
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
2422
{
2523
if (!IsEnabled(logLevel))

src/Runpath.Extensions.Logging.AzureEventHubs/AzureEventHubsLoggerProvider.cs

+2-18
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,26 @@ namespace Runpath.Extensions.Logging.AzureEventHubs
88
[ProviderAlias("AzureEventHubs")]
99
public class AzureEventHubsLoggerProvider : ILoggerProvider, ISupportExternalScope
1010
{
11-
private readonly IOptionsMonitor<AzureEventHubsLoggerOptions> options;
1211
private readonly ConcurrentDictionary<string, AzureEventHubsLogger> loggers;
1312
private readonly IAzureEventHubsLoggerFormatter formatter;
1413
private readonly IAzureEventHubsLoggerProcessor processor;
1514

1615
private IDisposable optionsReloadToken;
1716
private IExternalScopeProvider scopeProvider;
1817

19-
public AzureEventHubsLoggerProvider(IOptionsMonitor<AzureEventHubsLoggerOptions> options, IAzureEventHubsLoggerFormatter formatter, IAzureEventHubsLoggerProcessor processor)
18+
public AzureEventHubsLoggerProvider(IAzureEventHubsLoggerFormatter formatter, IAzureEventHubsLoggerProcessor processor)
2019
{
21-
this.options = options;
22-
this.loggers = new ConcurrentDictionary<string, AzureEventHubsLogger>();
23-
24-
ReloadLoggerOptions(options.CurrentValue);
25-
2620
this.formatter = formatter;
2721
this.processor = processor;
22+
this.loggers = new ConcurrentDictionary<string, AzureEventHubsLogger>();
2823

2924
SetScopeProvider(NullExternalScopeProvider.Instance);
3025
}
3126

32-
private void ReloadLoggerOptions(AzureEventHubsLoggerOptions options)
33-
{
34-
foreach (var logger in this.loggers)
35-
{
36-
logger.Value.Options = options;
37-
}
38-
39-
this.optionsReloadToken = this.options.OnChange(ReloadLoggerOptions);
40-
}
41-
4227
/// <inheritdoc/>
4328
public ILogger CreateLogger(string name) => this.loggers.GetOrAdd(name,
4429
_ => new AzureEventHubsLogger(name, this.formatter, this.processor)
4530
{
46-
Options = this.options.CurrentValue,
4731
ScopeProvider = this.scopeProvider
4832
});
4933

src/Runpath.Extensions.Logging.AzureEventHubs/DefaultAzureEventHubsLoggerProcessor.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ namespace Runpath.Extensions.Logging.AzureEventHubs
1212
/// </summary>
1313
internal class DefaultAzureEventHubsLoggerProcessor : IAzureEventHubsLoggerProcessor
1414
{
15-
private readonly IOptionsMonitor<AzureEventHubsLoggerOptions> options;
1615
private readonly Channel<EventData> channel;
1716

1817
private IDisposable optionsReloadToken;
1918
private EventHubClient eventHubClient;
2019

2120
public DefaultAzureEventHubsLoggerProcessor(IOptionsMonitor<AzureEventHubsLoggerOptions> options)
2221
{
23-
this.options = options;
24-
2522
ReloadLoggerOptions(options.CurrentValue);
23+
this.optionsReloadToken = options.OnChange(ReloadLoggerOptions);
2624

2725
this.channel = Channel.CreateBounded<EventData>(new BoundedChannelOptions(options.CurrentValue.QueueDepth)
2826
{
@@ -38,8 +36,6 @@ public DefaultAzureEventHubsLoggerProcessor(IOptionsMonitor<AzureEventHubsLogger
3836
private void ReloadLoggerOptions(AzureEventHubsLoggerOptions options)
3937
{
4038
this.eventHubClient = options.EventHubClientFactory?.Invoke(options);
41-
42-
this.optionsReloadToken = this.options.OnChange(ReloadLoggerOptions);
4339
}
4440

4541
public void Process(EventData eventData) => this.channel.Writer.TryWrite(eventData);

src/Runpath.Extensions.Logging.AzureEventHubs/Runpath.Extensions.Logging.AzureEventHubs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Company>Runpath Digital</Company>
88
<Authors>Runpath Digital</Authors>
99
<Description>Azure Event Hubs logger provider implementation for Microsoft.Extensions.Logging.</Description>
10-
<Version>1.1.0</Version>
10+
<Version>1.2.0</Version>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1212
<PackageTags>logging azure event hubs</PackageTags>
1313
<PackageProjectUrl>https://github.com/Runpath/Runpath.Extensions.Logging.AzureEventHubs</PackageProjectUrl>

0 commit comments

Comments
 (0)