Ejemplo n.º 1
0
        public static async Task RunCompositionRootWithDefaultLoggingExampleAsync()
        {
            using (var container = new ServiceContainer())
            {
                Console.WriteLine("************** COMPOSITION ROOT WITH DEFAULT LOGGING RUN BEGIN **************\n");

                container.RegisterFrom <CompositionRoot>();
                container.RegisterInstance(typeof(ILogger), new LoggerConfiguration().WriteTo.Console().CreateLogger());
                container.AddAsyncPipelineComponentLogging();

                var pipeline = container.GetInstance <IAsyncPipeline <ExamplePipelinePayload> >(PipelineNames.ExceptionPipelineName);

                var payload = new ExamplePipelinePayload();
                try
                {
                    payload = await pipeline.ExecuteAsync(payload, CancellationToken.None);
                }
                catch (PipelineExecutionException exception)
                {
                    container.GetInstance <ILogger>()
                    .Error(
                        exception,
                        "An exception was thrown by pipeline component named '{ComponentName}'",
                        exception.ThrowingComponent.Name);
                }

                Console.WriteLine($"Pipeline has completed execution and returned '{payload.Messages.Count}' component messages.");
                Console.WriteLine("\n************** COMPOSITION ROOT WITH DEFAULT LOGGING RUN END **************\n\n");
            }
        }
Ejemplo n.º 2
0
 // ReSharper disable once RedundantOverriddenMember
 public override Task <ExamplePipelinePayload> ExecuteAsync(ExamplePipelinePayload payload, CancellationToken cancellationToken)
 => base.ExecuteAsync(payload, cancellationToken);