Rau*_*ian 4 c# database-migration fluent-migrator
有没有办法使用In-Process Migration Runner生成 SQL 文件输出,类似于使用工具中的-output 命令参数可以实现的结果dotnet-fm。
我在 中找不到任何属性、字段或方法IMigrationRunner,IMigrationRunnerBuilder或者在IMigrationProcessorOptions设置中找不到任何属性、字段或方法来配置输出。
我错过了什么吗?
小智 6
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;
});
Run Code Online (Sandbox Code Playgroud)
您还可以编写一个扩展方法和一个装饰器来添加自定义日志记录提供程序,以防您想将其记录在控制台以外的其他地方。但我相信 fluentMigrator 已经开箱即用地支持这一点。
| 归档时间: |
|
| 查看次数: |
1009 次 |
| 最近记录: |