Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing disposed channel after config refresh #396

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Elastic.Extensions.Logging/ElasticsearchLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ namespace Elastic.Extensions.Logging
public class ElasticsearchLogger : ILogger
{
private readonly string _categoryName;
private readonly IBufferedChannel<LogEvent> _channel;
private IBufferedChannel<LogEvent> _channel => _channelProvider.GetChannel();
private readonly IChannelProvider _channelProvider;
private readonly ElasticsearchLoggerOptions _options;
private readonly IExternalScopeProvider? _scopeProvider;

/// <inheritdoc cref="IChannelDiagnosticsListener"/>
public IChannelDiagnosticsListener? DiagnosticsListener { get; }
public IChannelDiagnosticsListener? DiagnosticsListener => _channel.DiagnosticsListener;

internal ElasticsearchLogger(
string categoryName,
IBufferedChannel<LogEvent> channel,
IChannelProvider channelProvider,
ElasticsearchLoggerOptions options,
IExternalScopeProvider? scopeProvider
)
{
_categoryName = categoryName;
_channel = channel;
_options = options;
_channelProvider = channelProvider;
_scopeProvider = scopeProvider;
DiagnosticsListener = channel.DiagnosticsListener;
}

/// <inheritdoc cref="ILogger.BeginScope{TState}"/>
Expand Down
7 changes: 5 additions & 2 deletions src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Elastic.Extensions.Logging
/// instances to <see cref="LoggerFactory"/>
/// </summary>
[ProviderAlias("Elasticsearch")]
public class ElasticsearchLoggerProvider : ILoggerProvider, ISupportExternalScope
public class ElasticsearchLoggerProvider : ILoggerProvider, ISupportExternalScope, IChannelProvider
{
private readonly IChannelSetup[] _channelConfigurations;
private readonly IOptionsMonitor<ElasticsearchLoggerOptions> _options;
Expand Down Expand Up @@ -59,7 +59,7 @@ IEnumerable<IChannelSetup> channelConfigurations

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

/// <inheritdoc cref="IDisposable.Dispose"/>
public void Dispose()
Expand Down Expand Up @@ -189,5 +189,8 @@ private IBufferedChannel<LogEvent> CreatIngestChannel(ElasticsearchLoggerOptions
return channel;
}
}

/// <inheritdoc cref="IChannelProvider.GetChannel"/>
public IBufferedChannel<LogEvent> GetChannel() => _shipper;
}
}
20 changes: 20 additions & 0 deletions src/Elastic.Extensions.Logging/IChannelProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Channels;

namespace Elastic.Extensions.Logging
{
/// <summary>
/// Instantiates and manages <see cref="IBufferedChannel{TEvent}"/>
/// </summary>
internal interface IChannelProvider
{
/// <summary>
/// Provides <see cref="IBufferedChannel{TEvent}"/> instance managed by provider
/// </summary>
/// <returns></returns>
IBufferedChannel<LogEvent> GetChannel();
}
}
Loading