Skip to content

Commit

Permalink
Added logging (#52)
Browse files Browse the repository at this point in the history
* Added logging

* added more logs
  • Loading branch information
mvSapphire authored Feb 8, 2024
1 parent 423e0e0 commit d6c9086
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 74 deletions.
2 changes: 2 additions & 0 deletions samples/PowerPipe.Sample/PowerPipe.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions samples/PowerPipe.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using PowerPipe.Sample.Steps;

namespace PowerPipe.Sample;
Expand Down Expand Up @@ -30,6 +31,13 @@ private static IServiceProvider ConfigureServices()
.AddScoped(typeof(SampleGenericStep<>));
});

services.AddLogging(options =>
{
options
.AddConsole()
.SetMinimumLevel(LogLevel.Debug);
});

services.AddSingleton<SamplePipeline>();
var serviceProvider = services.BuildServiceProvider();

Expand Down
1 change: 0 additions & 1 deletion samples/PowerPipe.Sample/Steps/SampleGenericStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class SampleGenericStep<T>: IPipelineStep<SamplePipelineContext>

public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleGenericStep<T>)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep1 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep1)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep2 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep2)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep3.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep3 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep3)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class SampleParallelStep4 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep4)} Executed");

throw new InvalidOperationException();

// return ValueTask.CompletedTask;
Expand Down
3 changes: 0 additions & 3 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep5.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,8 +8,6 @@ public class SampleParallelStep5 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep5)} Executed");

// throw new InvalidOperationException();

return ValueTask.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep5Compensation : IPipelineCompensationStep<SampleP
{
public ValueTask CompensateAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep5Compensation)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep6.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep6 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep6)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleParallelStep7.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleParallelStep7 : IPipelineParallelStep<SamplePipelineContext>
{
public ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleParallelStep7)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep1 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep1)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep1Compensation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleStep1Compensation : IPipelineCompensationStep<SamplePipelineC
{
public ValueTask CompensateAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep1Compensation)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep2 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep2)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep2Compensation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleStep2Compensation : IPipelineCompensationStep<SamplePipelineC
{
public ValueTask CompensateAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep2Compensation)} Executed");
return ValueTask.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep3.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep3 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep3)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep4.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep4 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep4)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep5.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep5 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep5)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep6.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,7 +9,6 @@ public class SampleStep6 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep6)} Executed");
await NextStep.ExecuteAsync(context, cancellationToken);
}
}
3 changes: 0 additions & 3 deletions samples/PowerPipe.Sample/Steps/SampleStep7.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -10,8 +9,6 @@ public class SampleStep7 : IPipelineStep<SamplePipelineContext>
public IPipelineStep<SamplePipelineContext> NextStep { get; set; }
public async ValueTask ExecuteAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep7)} Executed");

// throw new InvalidOperationException();

await NextStep.ExecuteAsync(context, cancellationToken);
Expand Down
2 changes: 0 additions & 2 deletions samples/PowerPipe.Sample/Steps/SampleStep7Compensation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using PowerPipe.Interfaces;
Expand All @@ -9,7 +8,6 @@ public class SampleStep7Compensation : IPipelineCompensationStep<SamplePipelineC
{
public ValueTask CompensateAsync(SamplePipelineContext context, CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(SampleStep7Compensation)} Executed");
return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

</Project>
15 changes: 10 additions & 5 deletions src/PowerPipe/Builder/PipelineBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using PowerPipe.Builder.Steps;
using PowerPipe.Interfaces;

Expand All @@ -15,6 +16,7 @@ public sealed class PipelineBuilder<TContext, TResult>
where TResult : class
{
private readonly IPipelineStepFactory _pipelineStepFactory;
private readonly ILoggerFactory _loggerFactory;
private volatile TContext _context;

internal List<InternalStep<TContext>> Steps { get; } = new();
Expand All @@ -32,6 +34,7 @@ public PipelineBuilder(IPipelineStepFactory pipelineStepFactory, TContext contex

_pipelineStepFactory = pipelineStepFactory;
_context = context;
_loggerFactory = pipelineStepFactory.ServiceProvider.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
}

/// <summary>
Expand All @@ -42,7 +45,7 @@ public PipelineBuilder(IPipelineStepFactory pipelineStepFactory, TContext contex
public PipelineBuilder<TContext, TResult> Add<T>()
where T : IStepBase<TContext>
{
Steps.Add(new LazyStep<TContext>(_pipelineStepFactory.Create<T, TContext>));
Steps.Add(new LazyStep<TContext>(_pipelineStepFactory.Create<T, TContext>, _loggerFactory));

return this;
}
Expand All @@ -56,7 +59,9 @@ public PipelineBuilder<TContext, TResult> Add<T>()
public PipelineBuilder<TContext, TResult> AddIf<T>(Predicate<TContext> predicate)
where T : IStepBase<TContext>
{
Steps.Add(new AddIfStep<TContext>(predicate, new LazyStep<TContext>(_pipelineStepFactory.Create<T, TContext>)));
Steps.Add(new AddIfStep<TContext>(
predicate,
new LazyStep<TContext>(_pipelineStepFactory.Create<T, TContext>, _loggerFactory)));

return this;
}
Expand All @@ -74,8 +79,8 @@ public PipelineBuilder<TContext, TResult> AddIfElse<TIf, TElse>(Predicate<TConte
{
Steps.Add(new AddIfElseStep<TContext>(
predicate,
new LazyStep<TContext>(_pipelineStepFactory.Create<TIf, TContext>),
new LazyStep<TContext>(_pipelineStepFactory.Create<TElse, TContext>)));
new LazyStep<TContext>(_pipelineStepFactory.Create<TIf, TContext>, _loggerFactory),
new LazyStep<TContext>(_pipelineStepFactory.Create<TElse, TContext>, _loggerFactory)));

return this;
}
Expand Down Expand Up @@ -151,4 +156,4 @@ public IPipeline<TResult> Build()

return new Pipeline<TContext, TResult>(_context, Steps);
}
}
}
Loading

0 comments on commit d6c9086

Please sign in to comment.