| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | using Elsa.Diagnostics.StructuredLogs.Contracts; |
| | | 3 | | using Elsa.Diagnostics.StructuredLogs.Models; |
| | | 4 | | using Elsa.Diagnostics.StructuredLogs.Options; |
| | | 5 | | using Microsoft.Extensions.Options; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Diagnostics.StructuredLogs.Providers.InMemory; |
| | | 8 | | |
| | | 9 | | public class InMemoryStructuredLogProvider : IStructuredLogStreamProvider |
| | | 10 | | { |
| | | 11 | | private readonly InMemoryStructuredLogStore _store; |
| | | 12 | | private readonly InMemoryStructuredLogLiveFeed _liveFeed; |
| | | 13 | | |
| | 6 | 14 | | public InMemoryStructuredLogProvider(IOptions<StructuredLogsOptions> options, IStructuredLogSourceRegistry sourceReg |
| | | 15 | | { |
| | 6 | 16 | | _store = new(options, sourceRegistry); |
| | 6 | 17 | | _liveFeed = new(options); |
| | 6 | 18 | | } |
| | | 19 | | |
| | 0 | 20 | | public InMemoryStructuredLogProvider(InMemoryStructuredLogStore store, InMemoryStructuredLogLiveFeed liveFeed) |
| | | 21 | | { |
| | 0 | 22 | | _store = store; |
| | 0 | 23 | | _liveFeed = liveFeed; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public async ValueTask PublishAsync(StructuredLogEvent logEvent, CancellationToken cancellationToken = default) |
| | | 27 | | { |
| | 15 | 28 | | await _store.WriteAsync(logEvent, cancellationToken); |
| | 15 | 29 | | await _liveFeed.PublishAsync(logEvent, cancellationToken); |
| | 15 | 30 | | } |
| | | 31 | | |
| | | 32 | | public ValueTask<RecentStructuredLogsResult> GetRecentAsync(StructuredLogFilter filter, CancellationToken cancellati |
| | | 33 | | { |
| | 4 | 34 | | return _store.QueryAsync(filter, cancellationToken); |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public async IAsyncEnumerable<StructuredLogEvent> SubscribeAsync(StructuredLogFilter filter, [EnumeratorCancellation |
| | | 38 | | { |
| | 3 | 39 | | await foreach (var item in SubscribeWithDroppedEventsAsync(filter, cancellationToken)) |
| | | 40 | | { |
| | 1 | 41 | | if (item.LogEvent != null) |
| | 1 | 42 | | yield return item.LogEvent; |
| | | 43 | | } |
| | 1 | 44 | | } |
| | | 45 | | |
| | | 46 | | public IAsyncEnumerable<StructuredLogStreamItem> SubscribeWithDroppedEventsAsync(StructuredLogFilter filter, Cancell |
| | | 47 | | { |
| | 2 | 48 | | return _liveFeed.SubscribeAsync(filter, cancellationToken); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public ValueTask<IReadOnlyCollection<StructuredLogSource>> ListSourcesAsync(CancellationToken cancellationToken = de |
| | | 52 | | { |
| | 0 | 53 | | return _store.ListSourcesAsync(cancellationToken); |
| | | 54 | | } |
| | | 55 | | } |