| | | 1 | | using Elsa.Common; |
| | | 2 | | using Elsa.Diagnostics.StructuredLogs.Features; |
| | | 3 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Contracts; |
| | | 4 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Extensions; |
| | | 5 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Options; |
| | | 6 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Features; |
| | | 7 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Options; |
| | | 8 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Services; |
| | | 9 | | using Elsa.Extensions; |
| | | 10 | | using Microsoft.Extensions.DependencyInjection; |
| | | 11 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 12 | | using Microsoft.Extensions.Options; |
| | | 13 | | |
| | | 14 | | namespace Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Extensions; |
| | | 15 | | |
| | | 16 | | public static class SqliteStructuredLogsModuleExtensions |
| | | 17 | | { |
| | | 18 | | public static StructuredLogsFeature UseSqliteStorage(this StructuredLogsFeature feature, string connectionString, Ac |
| | | 19 | | { |
| | 0 | 20 | | feature.Module.Use<SqliteStructuredLogPersistenceFeature>(sqlite => |
| | 0 | 21 | | { |
| | 0 | 22 | | sqlite.ConfigureOptions = options => |
| | 0 | 23 | | { |
| | 0 | 24 | | options.ConnectionString = connectionString; |
| | 0 | 25 | | configure?.Invoke(options); |
| | 0 | 26 | | }; |
| | 0 | 27 | | }); |
| | | 28 | | |
| | 0 | 29 | | return feature; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public static StructuredLogsFeature UseSqliteStorage(this StructuredLogsFeature feature, Action<SqliteStructuredLogO |
| | | 33 | | { |
| | 0 | 34 | | feature.Module.Use<SqliteStructuredLogPersistenceFeature>(sqlite => sqlite.ConfigureOptions = configure); |
| | 0 | 35 | | return feature; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public static IServiceCollection AddSqliteStructuredLogPersistence(this IServiceCollection services, Action<SqliteSt |
| | | 39 | | { |
| | 20 | 40 | | if (configure != null) |
| | 20 | 41 | | services.Configure(configure); |
| | | 42 | | |
| | 20 | 43 | | services.AddOptions<SqliteStructuredLogOptions>(); |
| | 38 | 44 | | services.AddOptions<RelationalStructuredLogOptions>().Configure<IOptions<SqliteStructuredLogOptions>>((relationa |
| | | 45 | | |
| | 20 | 46 | | services.TryAddSingleton<IRelationalStructuredLogConnectionFactory, SqliteStructuredLogConnectionFactory>(); |
| | 20 | 47 | | services.TryAddSingleton<IRelationalStructuredLogDialect, SqliteStructuredLogDialect>(); |
| | 20 | 48 | | services.TryAddSingleton<IStructuredLogSchemaMigrator, SqliteStructuredLogSchemaMigrator>(); |
| | 20 | 49 | | services.TryAddSingleton<SqliteStructuredLogStartupService>(); |
| | 26 | 50 | | services.AddHostedService(sp => sp.GetRequiredService<SqliteStructuredLogStartupService>()); |
| | 23 | 51 | | services.AddScoped<IStartupTask>(sp => sp.GetRequiredService<SqliteStructuredLogStartupService>()); |
| | 20 | 52 | | services.AddRelationalStructuredLogPersistence(); |
| | | 53 | | |
| | 20 | 54 | | return services; |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | private static void Copy(RelationalStructuredLogOptions source, RelationalStructuredLogOptions target) |
| | | 58 | | { |
| | 18 | 59 | | target.WriteQueue.Capacity = source.WriteQueue.Capacity; |
| | 18 | 60 | | target.WriteQueue.BatchSize = source.WriteQueue.BatchSize; |
| | 18 | 61 | | target.WriteQueue.FlushInterval = source.WriteQueue.FlushInterval; |
| | 18 | 62 | | target.WriteQueue.ShutdownFlushTimeout = source.WriteQueue.ShutdownFlushTimeout; |
| | 18 | 63 | | target.Retention.MaxAge = source.Retention.MaxAge; |
| | 18 | 64 | | target.Retention.MaxRows = source.Retention.MaxRows; |
| | 18 | 65 | | target.Retention.CleanupOnStartup = source.Retention.CleanupOnStartup; |
| | 18 | 66 | | } |
| | | 67 | | } |