Initial version

This commit is contained in:
2026-02-28 07:19:29 +01:00
parent b5f4af6930
commit 3f3356eb4a
183 changed files with 90406 additions and 63 deletions

View 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();
}
}
}