如何记录 subsonic3 sql
我开始开发一个基于 subsonic3 (用于查询)和 log4net (用于日志)的新 asp.net 应用程序,并且想知道如何将 subsonic3 与 log4net 接口,以便 log4net 记录 subsonic 使用的底层 sql。
这是我到目前为止所拥有的:
public static IEnumerable<arma_ocorrencium> ListArmasOcorrencia()
{
if (logger.IsInfoEnabled)
{
logger.Info("ListarArmasOcorrencia: start");
}
var db = new BdvdDB();
var select = from p in db.arma_ocorrencia
select p;
var results = select.ToList<arma_ocorrencium>(); //Execute the query here
if (logger.IsInfoEnabled)
{
// log sql here
}
if (logger.IsInfoEnabled)
{
logger.Info("ListarArmasOcorrencia: end");
}
return results;
}
I'm starting to develop a new asp.net application based on subsonic3 (for queries) and log4net (for logs) and would like to know how to interface subsonic3 with log4net so that log4net logs the underlying sql used by subsonic.
This is what I have so far:
public static IEnumerable<arma_ocorrencium> ListArmasOcorrencia()
{
if (logger.IsInfoEnabled)
{
logger.Info("ListarArmasOcorrencia: start");
}
var db = new BdvdDB();
var select = from p in db.arma_ocorrencia
select p;
var results = select.ToList<arma_ocorrencium>(); //Execute the query here
if (logger.IsInfoEnabled)
{
// log sql here
}
if (logger.IsInfoEnabled)
{
logger.Info("ListarArmasOcorrencia: end");
}
return results;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Provider 类的 Log 属性:
将您的 SQL 语句记录到控制台。如果您想使用 log4net 或类似的东西,您将必须编写一个小的中介类来实现 TextWriter 并将所有收到的输入重定向到 log4net。
You can use the Log property of the Provider class:
will log your SQL statements to the console. If you want to use log4net or something similar you will have to write a small mediator class that implements TextWriter and redirects all received input to log4net.
您可以这样获取生成的sql:
确保您使用的是3.0.0.4或更高版本。
干杯
You can get the generated sql like this:
Make sure you are using the version 3.0.0.4 or above.
Cheers