How do I target another database with tracker-enabled-dbcontext

Solution 1:

You can try leveraging OnAuditLogGenerated event. Something along this lines:

public sealed class MyDBContext : TrackerContext
{
    public MyDBContext ()
    {
        OnAuditLogGenerated += SaveToAnotherDb;
    }

    private void SaveToAnotherDb(object? sender, AuditLogGeneratedEventArgs args)
    {
        var auditLog = args.Log;

        using (MacsAuditDbContext db = new MacsAuditDbContext())
        {
            db.AuditLog.Add(auditLog);
            db.SaveChanges();
        }

        //skips saving to local database
        args.SkipSavingLog = true;
    }

    protected override void Dispose(bool disposing)
    {
        OnAuditLogGenerated -= SaveToAnotherDb;
        base.Dispose(disposing);
    }
}