From 1ac3a37e167fa38af72130868b0cc6a2c7c8f9cc Mon Sep 17 00:00:00 2001 From: Eben Date: Mon, 5 Aug 2024 17:30:43 +0200 Subject: [PATCH] Package upgrade. --- .../AddProjectionPipelineLogger.cs | 56 ++++++++++ .../AddProjectionPipelineObserver.cs | 46 ++++++++ .../AssembleEventEnvelopePipelineLogger.cs | 56 ++++++++++ .../AssembleEventEnvelopePipelineObserver.cs | 101 ++++++++++++++++++ .../EventProcessingPipelineLogger.cs | 1 - .../EventProcessorStartupPipelineLogger.cs | 56 ++++++++++ .../EventProcessorStartupPipelineObserver.cs | 79 ++++++++++++++ .../GetEventEnvelopePipelineLogger.cs | 56 ++++++++++ .../GetEventEnvelopePipelineObserver.cs | 101 ++++++++++++++++++ .../GetEventStreamPipelineLogger.cs | 56 ++++++++++ .../GetEventStreamPipelineObserver.cs | 68 ++++++++++++ Shuttle.Recall.Logging/PipelineObserver.cs | 5 +- .../RemoveEventStreamPipelineLogger.cs | 56 ++++++++++ .../RemoveEventStreamPipelineObserver.cs | 46 ++++++++ .../SaveEventStreamPipelineLogger.cs | 56 ++++++++++ .../SaveEventStreamPipelineObserver.cs | 90 ++++++++++++++++ .../ServiceCollectionExtensions.cs | 7 ++ 17 files changed, 933 insertions(+), 3 deletions(-) create mode 100644 Shuttle.Recall.Logging/AddProjectionPipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/AddProjectionPipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/AssembleEventEnvelopePipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/AssembleEventEnvelopePipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/EventProcessorStartupPipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/EventProcessorStartupPipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/GetEventEnvelopePipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/GetEventEnvelopePipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/GetEventStreamPipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/GetEventStreamPipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/RemoveEventStreamPipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/RemoveEventStreamPipelineObserver.cs create mode 100644 Shuttle.Recall.Logging/SaveEventStreamPipelineLogger.cs create mode 100644 Shuttle.Recall.Logging/SaveEventStreamPipelineObserver.cs diff --git a/Shuttle.Recall.Logging/AddProjectionPipelineLogger.cs b/Shuttle.Recall.Logging/AddProjectionPipelineLogger.cs new file mode 100644 index 0000000..4113040 --- /dev/null +++ b/Shuttle.Recall.Logging/AddProjectionPipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class AddProjectionPipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(AddProjectionPipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public AddProjectionPipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new AddProjectionPipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/AddProjectionPipelineObserver.cs b/Shuttle.Recall.Logging/AddProjectionPipelineObserver.cs new file mode 100644 index 0000000..a4be0f6 --- /dev/null +++ b/Shuttle.Recall.Logging/AddProjectionPipelineObserver.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class AddProjectionPipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public AddProjectionPipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnBeforeAddProjection pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnBeforeAddProjection pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAddProjection pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAddProjection pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterAddProjection pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterAddProjection pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineLogger.cs b/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineLogger.cs new file mode 100644 index 0000000..557fe81 --- /dev/null +++ b/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class AssembleEventEnvelopePipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(AssembleEventEnvelopePipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public AssembleEventEnvelopePipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new AssembleEventEnvelopePipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineObserver.cs b/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineObserver.cs new file mode 100644 index 0000000..cf80065 --- /dev/null +++ b/Shuttle.Recall.Logging/AssembleEventEnvelopePipelineObserver.cs @@ -0,0 +1,101 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class AssembleEventEnvelopePipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public AssembleEventEnvelopePipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnAssembleEventEnvelope pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAssembleEventEnvelope pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterAssembleEventEnvelope pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterAssembleEventEnvelope pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnSerializeEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnSerializeEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterSerializeEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterSerializeEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnEncryptEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnEncryptEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterEncryptEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterEncryptEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnCompressEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnCompressEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterCompressEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterCompressEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/EventProcessingPipelineLogger.cs b/Shuttle.Recall.Logging/EventProcessingPipelineLogger.cs index 7fe24e1..b8c342f 100644 --- a/Shuttle.Recall.Logging/EventProcessingPipelineLogger.cs +++ b/Shuttle.Recall.Logging/EventProcessingPipelineLogger.cs @@ -24,7 +24,6 @@ public EventProcessingPipelineLogger(ILogger logg if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) { _pipelineFactory.PipelineCreated += OnPipelineCreated; - } } diff --git a/Shuttle.Recall.Logging/EventProcessorStartupPipelineLogger.cs b/Shuttle.Recall.Logging/EventProcessorStartupPipelineLogger.cs new file mode 100644 index 0000000..dcf14d5 --- /dev/null +++ b/Shuttle.Recall.Logging/EventProcessorStartupPipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class EventProcessorStartupPipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(EventProcessorStartupPipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public EventProcessorStartupPipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new EventProcessorStartupPipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/EventProcessorStartupPipelineObserver.cs b/Shuttle.Recall.Logging/EventProcessorStartupPipelineObserver.cs new file mode 100644 index 0000000..bd48692 --- /dev/null +++ b/Shuttle.Recall.Logging/EventProcessorStartupPipelineObserver.cs @@ -0,0 +1,79 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class EventProcessorStartupPipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public EventProcessorStartupPipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnStartEventProcessing pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnStartEventProcessing pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterStartEventProcessing pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterStartEventProcessing pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnConfigureThreadPools pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnConfigureThreadPools pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterConfigureThreadPools pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterConfigureThreadPools pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnStartThreadPools pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnStartThreadPools pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterStartThreadPools pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterStartThreadPools pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/GetEventEnvelopePipelineLogger.cs b/Shuttle.Recall.Logging/GetEventEnvelopePipelineLogger.cs new file mode 100644 index 0000000..2048de5 --- /dev/null +++ b/Shuttle.Recall.Logging/GetEventEnvelopePipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class GetEventEnvelopePipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(GetEventEnvelopePipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public GetEventEnvelopePipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new GetEventEnvelopePipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/GetEventEnvelopePipelineObserver.cs b/Shuttle.Recall.Logging/GetEventEnvelopePipelineObserver.cs new file mode 100644 index 0000000..b9c6cb9 --- /dev/null +++ b/Shuttle.Recall.Logging/GetEventEnvelopePipelineObserver.cs @@ -0,0 +1,101 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class GetEventEnvelopePipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public GetEventEnvelopePipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnDeserializeEventEnvelope pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnDeserializeEventEnvelope pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterDeserializeEventEnvelope pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterDeserializeEventEnvelope pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnDecompressEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnDecompressEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterDecompressEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterDecompressEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnDecryptEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnDecryptEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterDecryptEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterDecryptEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnDeserializeEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnDeserializeEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterDeserializeEvent pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterDeserializeEvent pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/GetEventStreamPipelineLogger.cs b/Shuttle.Recall.Logging/GetEventStreamPipelineLogger.cs new file mode 100644 index 0000000..99ed109 --- /dev/null +++ b/Shuttle.Recall.Logging/GetEventStreamPipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class GetEventStreamPipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(GetEventStreamPipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public GetEventStreamPipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new GetEventStreamPipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/GetEventStreamPipelineObserver.cs b/Shuttle.Recall.Logging/GetEventStreamPipelineObserver.cs new file mode 100644 index 0000000..160c7c6 --- /dev/null +++ b/Shuttle.Recall.Logging/GetEventStreamPipelineObserver.cs @@ -0,0 +1,68 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class GetEventStreamPipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public GetEventStreamPipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnBeforeGetStreamEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnBeforeGetStreamEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnGetStreamEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnGetStreamEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterGetStreamEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterGetStreamEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAssembleEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAssembleEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterAssembleEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterAssembleEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/PipelineObserver.cs b/Shuttle.Recall.Logging/PipelineObserver.cs index f481662..d815b0a 100644 --- a/Shuttle.Recall.Logging/PipelineObserver.cs +++ b/Shuttle.Recall.Logging/PipelineObserver.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Shuttle.Core.Contract; @@ -40,7 +41,7 @@ protected async Task Trace(IPipelineEvent pipelineEvent, string message = "") Increment(type); - _logger.LogTrace($"[{type.Name} (thread {System.Threading.Thread.CurrentThread.ManagedThreadId}) / {_eventCounts[type]}] : pipeline = {pipelineEvent.Pipeline.GetType().FullName}{(string.IsNullOrEmpty(message) ? string.Empty : $" / {message}")}"); + _logger.LogTrace($"[{type.Name}] : pipeline = {pipelineEvent.Pipeline.GetType().FullName}{(string.IsNullOrEmpty(message) ? string.Empty : $" / {message}")} / call count = {_eventCounts[type]} / managed thread id = {Thread.CurrentThread.ManagedThreadId}"); await Task.CompletedTask; } @@ -78,7 +79,7 @@ public async Task ExecuteAsync(OnPipelineException pipelineEvent) var message = $"exception = '{pipelineEvent.Pipeline.Exception?.AllMessages()}'"; - _logger.LogError($"[{type.Name} (thread {System.Threading.Thread.CurrentThread.ManagedThreadId}) / {_eventCounts[type]}] : pipeline = {pipelineEvent.Pipeline.GetType().FullName}{(string.IsNullOrEmpty(message) ? string.Empty : $" / {message}")}"); + _logger.LogError($"[{type.Name}] : pipeline = {pipelineEvent.Pipeline.GetType().FullName}{(string.IsNullOrEmpty(message) ? string.Empty : $" / {message}")} / call count = {_eventCounts[type]} / managed thread id = {Thread.CurrentThread.ManagedThreadId}"); await Task.CompletedTask; } diff --git a/Shuttle.Recall.Logging/RemoveEventStreamPipelineLogger.cs b/Shuttle.Recall.Logging/RemoveEventStreamPipelineLogger.cs new file mode 100644 index 0000000..4b1f105 --- /dev/null +++ b/Shuttle.Recall.Logging/RemoveEventStreamPipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class RemoveEventStreamPipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(RemoveEventStreamPipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public RemoveEventStreamPipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new RemoveEventStreamPipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/RemoveEventStreamPipelineObserver.cs b/Shuttle.Recall.Logging/RemoveEventStreamPipelineObserver.cs new file mode 100644 index 0000000..521fc52 --- /dev/null +++ b/Shuttle.Recall.Logging/RemoveEventStreamPipelineObserver.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class RemoveEventStreamPipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public RemoveEventStreamPipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnBeforeRemoveEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnBeforeRemoveEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnRemoveEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnRemoveEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterRemoveEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterRemoveEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/SaveEventStreamPipelineLogger.cs b/Shuttle.Recall.Logging/SaveEventStreamPipelineLogger.cs new file mode 100644 index 0000000..50780c9 --- /dev/null +++ b/Shuttle.Recall.Logging/SaveEventStreamPipelineLogger.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Contract; +using Shuttle.Core.Pipelines; +using System.Threading.Tasks; +using System.Threading; +using System; + +namespace Shuttle.Recall.Logging +{ + public class SaveEventStreamPipelineLogger : IHostedService + { + private readonly Type _pipelineType = typeof(SaveEventStreamPipeline); + private readonly ILogger _logger; + private readonly IPipelineFactory _pipelineFactory; + private readonly IRecallLoggingConfiguration _recallLoggingConfiguration; + + public SaveEventStreamPipelineLogger(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration, IPipelineFactory pipelineFactory) + { + _logger = Guard.AgainstNull(logger, nameof(logger)); + _recallLoggingConfiguration = Guard.AgainstNull(recallLoggingConfiguration, nameof(recallLoggingConfiguration)); + _pipelineFactory = Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory)); + + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated += OnPipelineCreated; + } + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private void OnPipelineCreated(object sender, PipelineEventArgs args) + { + if (args.Pipeline.GetType() != _pipelineType) + { + return; + } + + args.Pipeline.RegisterObserver(new SaveEventStreamPipelineObserver(_logger, _recallLoggingConfiguration)); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_recallLoggingConfiguration.ShouldLogPipelineType(_pipelineType)) + { + _pipelineFactory.PipelineCreated -= OnPipelineCreated; + + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/SaveEventStreamPipelineObserver.cs b/Shuttle.Recall.Logging/SaveEventStreamPipelineObserver.cs new file mode 100644 index 0000000..a9a2ff0 --- /dev/null +++ b/Shuttle.Recall.Logging/SaveEventStreamPipelineObserver.cs @@ -0,0 +1,90 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Shuttle.Core.Pipelines; + +namespace Shuttle.Recall.Logging +{ + public class SaveEventStreamPipelineObserver : PipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver, + IPipelineObserver + { + public SaveEventStreamPipelineObserver(ILogger logger, IRecallLoggingConfiguration recallLoggingConfiguration) : base(logger, recallLoggingConfiguration) + { + } + + public void Execute(OnAssembleEventEnvelopes pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAssembleEventEnvelopes pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterAssembleEventEnvelopes pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterAssembleEventEnvelopes pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnBeforeSavePrimitiveEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnBeforeSavePrimitiveEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnSavePrimitiveEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnSavePrimitiveEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterSavePrimitiveEvents pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterSavePrimitiveEvents pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnCommitEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnCommitEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + + public void Execute(OnAfterCommitEventStream pipelineEvent) + { + Trace(pipelineEvent).GetAwaiter().GetResult(); + } + + public async Task ExecuteAsync(OnAfterCommitEventStream pipelineEvent) + { + await Trace(pipelineEvent); + } + } +} \ No newline at end of file diff --git a/Shuttle.Recall.Logging/ServiceCollectionExtensions.cs b/Shuttle.Recall.Logging/ServiceCollectionExtensions.cs index 1dd91d6..a9e7b18 100644 --- a/Shuttle.Recall.Logging/ServiceCollectionExtensions.cs +++ b/Shuttle.Recall.Logging/ServiceCollectionExtensions.cs @@ -22,6 +22,13 @@ public static IServiceCollection AddRecallLogging(this IServiceCollection servic }); services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); services.AddHostedService(); services.AddSingleton();