Initial version
This commit is contained in:
50
EonaCat.LogStack/EonaCatLoggerCore/Flows/FailoverFlow.cs
Normal file
50
EonaCat.LogStack/EonaCatLoggerCore/Flows/FailoverFlow.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using EonaCat.LogStack.Core;
|
||||
using EonaCat.LogStack.Flows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EonaCat.LogStack.Flows
|
||||
{
|
||||
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
|
||||
|
||||
public sealed class FailoverFlow : FlowBase
|
||||
{
|
||||
private readonly IFlow _primary;
|
||||
private readonly IFlow _secondary;
|
||||
|
||||
public FailoverFlow(IFlow primary, IFlow secondary)
|
||||
: base($"Failover({primary.Name})", primary.MinimumLevel)
|
||||
{
|
||||
_primary = primary ?? throw new ArgumentNullException(nameof(primary));
|
||||
_secondary = secondary ?? throw new ArgumentNullException(nameof(secondary));
|
||||
}
|
||||
|
||||
public override async Task<WriteResult> BlastAsync(LogEvent logEvent, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = await _primary.BlastAsync(logEvent, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == WriteResult.Success)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return await _secondary.BlastAsync(logEvent, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _primary.FlushAsync(cancellationToken);
|
||||
await _secondary.FlushAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await _primary.DisposeAsync();
|
||||
await _secondary.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user