AuditJournal Class
Assembly: CodeEffects.Rule.Audit.dll
Namespace: CodeEffects.Rule.Audit
Summary
Moves a journal folder into the Rule Repository database from outside the processes that wrote it.
Syntax
public static class AuditJournal
With Resilience set to Journal (the default in Asynchronous mode), every record is appended to a file in JournalFolder and a background thread of the AuditRecorder moves it into the database. That recorder also moves whatever processes that are gone left in the same folder, so for most applications neither method of this class is needed.
Use this class when you want no database traffic from your application process: a maintenance job, a start-up step, or one service that moves the journals of every process on the machine. Such a host still runs recorders, which keep journaling, and leaves the moving to this class.
Only one process at a time moves a folder. A recorder that finds this class moving its folder keeps journaling and does not move it. Records are never stored twice: each record carries its own ID, and the database stores only IDs it does not have yet, so a folder that is moved again after a crash writes nothing twice. Records whose rule or source version was deleted with its source object are discarded, and reported to OnProblem as RecordsDropped.
Methods
Replay(..)
Returns: System.Int64 - The number of records the database took.
public static long Replay(string folder, IDbProvider dbProvider, AuditSettings settings = null, CancellationToken cancellationToken = default(CancellationToken))
Moves every record that processes which are no longer running left in the journal folder into the database, then returns. It returns 0 when the folder does not exist. The file that a running process is still writing is not read; use Run(..) to follow it as it is written.
Parameters
Exceptions
System.ArgumentNullException - The provider is null.
System.ArgumentException - The folder is empty.
CodeEffects.Rule.Common.RuleException - Another process is moving the folder (control number CE20009), or a number in the settings is one that delivery cannot work with (CE20008).
Example
using CodeEffects.Rule.Audit;
// At start-up of a maintenance job
long moved = AuditJournal.Replay("/var/lib/myapp/audit", dbProvider);
Console.WriteLine(moved + " records moved.");
Run(..)
Returns: System.Int64 - The number of records the database took.
public static long Run(string folder, IDbProvider dbProvider, AuditSettings settings, CancellationToken cancellationToken)
Moves the journal folder until the token is cancelled: what processes that are gone left, and what live processes write, as they write it. While another process moves the folder it waits and tries again every few seconds. It returns when the token is cancelled, or at once when the folder does not exist. Run it on a thread of its own, or as the body of a service.
Parameters
Exceptions
System.ArgumentNullException - The provider is null.
System.ArgumentException - The folder is empty.
CodeEffects.Rule.Common.RuleException - A number in the settings is one that delivery cannot work with (CE20008).
Example
using System.Threading;
using CodeEffects.Rule.Audit;
var settings = new AuditSettings { BatchSize = 1000, OnProblem = p => logger.LogWarning(p.Message) };
// Blocks until the token is cancelled, such as when the service stops
long moved = AuditJournal.Run("/var/lib/myapp/audit", dbProvider, settings, stoppingToken);