有什么办法可以使用Dapper跟踪SQL日志? [英] Is there any way to trace\log the sql using Dapper?
问题描述
是否有一种方法可以将生成的sql转储到Debug日志中?我在winforms解决方案中使用了它,因此迷你分析器的想法对我不起作用。
同样的问题,并在进行了一些搜索后实现了一些代码,但没有现成的东西。我要分享的nuget MiniProfiler.Integrations 上有一个软件包。 p>
更新V2 :它支持与其他数据库服务器一起使用,对于MySQL,它需要具有 MiniProfiler.Integrations.MySql
以下是使用SQL的步骤服务器:
1。实例化连接
var factory = new SqlServerDbConnectionFactory(_connectionString);
使用(var connection = DbConnectionFactoryHelper.New(factory,CustomDbProfiler.Current))
{
//您的代码
}
2。完成所有工作后,如果需要,将所有命令写入文件中
File.WriteAllText( SqlScripts.txt,CustomDbProfiler.Current.ProfilerContext.BuildCommands());
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.
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 I would like to share.
Update V2: it supports to work with other database servers, for MySQL it requires to have MiniProfiler.Integrations.MySql
Below are steps to work with SQL Server:
1.Instantiate the connection
var factory = new SqlServerDbConnectionFactory(_connectionString);
using (var connection = DbConnectionFactoryHelper.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());
这篇关于有什么办法可以使用Dapper跟踪SQL日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!