Question: Is there a way to dump the generated sql to the Debug log or something? I'm using it in a winforms solution so the mini-profiler idea won't work for me.

Answer: 
I got the same issue and implemented some code after doing some search but having no ready-to-use stuff. There is a package on nuget [MiniProfiler.Integrations](https://www.nuget.org/packages/MiniProfiler.Integrations/) I would like to share.

**Update V2**: it supports to work with other database servers, for MySQL it requires to have [MiniProfiler.Integrations.MySql](https://www.nuget.org/packages/MiniProfiler.Integrations.MySql/)

Below are steps to work with SQL Server:

1.Instantiate the connection

```
var factory = new SqlServerDbConnectionFactory(_connectionString);
using (var connection = ProfiledDbConnectionFactory.New(factory, CustomDbProfiler.Current))
{
 // your code
}

```

2.After all works done, write all commands to a file if you want

```
File.WriteAllText("SqlScripts.txt", CustomDbProfiler.Current.ProfilerContext.BuildCommands());

```
Try [Dapper.Logging](https://github.com/hryz/Dapper.Logging/tree/71f4f3de06b95f131e84171698e0d3ed7cb52f83).
-----------------------------------------------------------------------------------------------------------

You can get it from NuGet. The way it works is you pass your code that creates your actual database connection into a factory that creates wrapped connections. Whenever a wrapped connection is opened or closed or you run a query against it, it will be logged. You can configure the logging message templates and other settings like whether SQL parameters are saved. Elapsed time is also saved.

In my opinion, the only downside is that the documentation is sparse, but I think that's just because it's a new project (as of this writing). I had to dig through the repo for a bit to understand it and to get it configured to my liking, but now it's working great.

From the documentation:

> 
> The tool consists of simple decorators for the `DbConnection` and
> `DbCommand` which track the execution time and write messages to the
> `ILogger<T>`. The `ILogger<T>` can be handled by any logging framework
> (e.g. Serilog). The result is similar to the default EF Core logging
> behavior.
> 
> 
> The lib declares a helper method for registering the
> `IDbConnectionFactory` in the IoC container. The connection factory is
> SQL Provider agnostic. That's why you have to specify the real factory
> method:
> 
> 
> 
> ```
> services.AddDbConnectionFactory(prv => new SqlConnection(conStr));
> 
> ```
> 
> After registration, the `IDbConnectionFactory` can be injected into
> classes that need a SQL connection.
> 
> 
> 
> ```
> private readonly IDbConnectionFactory _connectionFactory;
> public GetProductsHandler(IDbConnectionFactory connectionFactory)
> {
>     _connectionFactory = connectionFactory;
> }
> 
> ```
> 
> The `IDbConnectionFactory.CreateConnection` will return a decorated
> version that logs the activity.
> 
> 
> 
> ```
> using (DbConnection db = _connectionFactory.CreateConnection())
> {
>     //...
> }
> 
> ```
> 
>