简体   繁体   English

FluentMigrator 从进程内迁移运行器生成 SQL Output

[英]FluentMigrator generate SQL Output from In-Process Migration runner

Is there a way to generate SQL file output using the In-Process Migration Runner similarly to what can be achieved using -output command argument from the dotnet-fm tool.有没有一种方法可以使用In-Process Migration Runner生成 SQL 文件 output,类似于使用dotnet-fm工具中的-output 命令参数可以实现的方法。

I couldn't find any property, field or method in the IMigrationRunner , IMigrationRunnerBuilder or in the IMigrationProcessorOptions that would set configure the output.我在IMigrationRunnerIMigrationRunnerBuilderIMigrationProcessorOptions中找不到任何可以设置配置 output 的属性、字段或方法。

Am I missing something?我错过了什么吗?

https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.FluentMigratorConsoleLoggerProvider.html This page explains how to use a logging provider in fluent migrator. https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.FluentMigratorConsoleLoggerProvider.html This page explains how to use a logging provider in fluent migrator.

https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.LogFileFluentMigratorLoggerOptions.html Here you can go over the different options, such as writing the logs to SQL database or to a file, or just showing the SQL in the console (if you use a consoleloggingprovider). https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.LogFileFluentMigratorLoggerOptions.html Here you can go over the different options, such as writing the logs to SQL database or to a file, or just showing控制台中的 SQL(如果您使用控制台日志记录提供程序)。

Here is how to do it:这是如何做到的:

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

You could also write an extension method and a decorator to add custom logging providers, in case you want to log it somewhere else than the console.您还可以编写扩展方法和装饰器来添加自定义日志记录提供程序,以防您想在控制台以外的其他地方记录它。 but I believe fluentMigrator already supports this out of the box.但我相信 fluentMigrator 已经支持这个开箱即用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM