Skip to content

Commit 69a0822

Browse files
authored
Fixing disposed channel after config refresh (#396)
1 parent dfcdf93 commit 69a0822

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/Elastic.Extensions.Logging/ElasticsearchLogger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ namespace Elastic.Extensions.Logging
2121
public class ElasticsearchLogger : ILogger
2222
{
2323
private readonly string _categoryName;
24-
private readonly IBufferedChannel<LogEvent> _channel;
24+
private IBufferedChannel<LogEvent> _channel => _channelProvider.GetChannel();
25+
private readonly IChannelProvider _channelProvider;
2526
private readonly ElasticsearchLoggerOptions _options;
2627
private readonly IExternalScopeProvider? _scopeProvider;
2728

2829
/// <inheritdoc cref="IChannelDiagnosticsListener"/>
29-
public IChannelDiagnosticsListener? DiagnosticsListener { get; }
30+
public IChannelDiagnosticsListener? DiagnosticsListener => _channel.DiagnosticsListener;
3031

3132
internal ElasticsearchLogger(
3233
string categoryName,
33-
IBufferedChannel<LogEvent> channel,
34+
IChannelProvider channelProvider,
3435
ElasticsearchLoggerOptions options,
3536
IExternalScopeProvider? scopeProvider
3637
)
3738
{
3839
_categoryName = categoryName;
39-
_channel = channel;
4040
_options = options;
41+
_channelProvider = channelProvider;
4142
_scopeProvider = scopeProvider;
42-
DiagnosticsListener = channel.DiagnosticsListener;
4343
}
4444

4545
/// <inheritdoc cref="ILogger.BeginScope{TState}"/>

src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Elastic.Extensions.Logging
2525
/// instances to <see cref="LoggerFactory"/>
2626
/// </summary>
2727
[ProviderAlias("Elasticsearch")]
28-
public class ElasticsearchLoggerProvider : ILoggerProvider, ISupportExternalScope
28+
public class ElasticsearchLoggerProvider : ILoggerProvider, ISupportExternalScope, IChannelProvider
2929
{
3030
private readonly IChannelSetup[] _channelConfigurations;
3131
private readonly IOptionsMonitor<ElasticsearchLoggerOptions> _options;
@@ -59,7 +59,7 @@ IEnumerable<IChannelSetup> channelConfigurations
5959

6060
/// <inheritdoc cref="ILoggerProvider.CreateLogger"/>
6161
public ILogger CreateLogger(string name) =>
62-
new ElasticsearchLogger(name, _shipper, _options.CurrentValue, _scopeProvider);
62+
new ElasticsearchLogger(name, this, _options.CurrentValue, _scopeProvider);
6363

6464
/// <inheritdoc cref="IDisposable.Dispose"/>
6565
public void Dispose()
@@ -189,5 +189,8 @@ private IBufferedChannel<LogEvent> CreatIngestChannel(ElasticsearchLoggerOptions
189189
return channel;
190190
}
191191
}
192+
193+
/// <inheritdoc cref="IChannelProvider.GetChannel"/>
194+
public IBufferedChannel<LogEvent> GetChannel() => _shipper;
192195
}
193196
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Channels;
6+
7+
namespace Elastic.Extensions.Logging
8+
{
9+
/// <summary>
10+
/// Instantiates and manages <see cref="IBufferedChannel{TEvent}"/>
11+
/// </summary>
12+
internal interface IChannelProvider
13+
{
14+
/// <summary>
15+
/// Provides <see cref="IBufferedChannel{TEvent}"/> instance managed by provider
16+
/// </summary>
17+
/// <returns></returns>
18+
IBufferedChannel<LogEvent> GetChannel();
19+
}
20+
}

0 commit comments

Comments
 (0)