FluentMigrator 从进程中迁移运行程序生成 SQL 输出

FluentMigrator generate SQL Output from In-Process Migration runner

有没有办法使用 dotnet-fm 工具中的 In-Process Migration Runner similarly to what can be achieved using -output command argument 生成 SQL 文件输出。

我在 IMigrationRunnerIMigrationRunnerBuilderIMigrationProcessorOptions 中找不到任何 属性、字段或方法来设置配置输出。

我是不是漏掉了什么?

https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.FluentMigratorConsoleLoggerProvider.html 本页介绍如何在 Fluent Migrator 中使用日志提供程序。

https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.LogFileFluentMigratorLoggerOptions.html 在这里您可以查看不同的选项,例如将日志写入 SQL 数据库或文件,或者仅在控制台中显示 SQL(如果您使用 consoleloggingprovider)。

操作方法如下:

services
    .AddSingleton<ILoggerProvider, LogFileFluentMigratorLoggerProvider>()
    .Configure<LogFileFluentMigratorLoggerOptions>(
        opt =>
        {
            opt.OutputFileName = options.OutputFileName;
            opt.OutputGoBetweenStatements = targetIsSqlServer;
            opt.ShowSql = true;
        });

您还可以编写一个扩展方法和一个装饰器来添加自定义日志记录提供程序,以防您想在控制台以外的其他地方记录它。但我相信 fluentMigrator 已经支持开箱即用。