开发者

How to log subsonic3 sql

开发者 https://www.devze.com 2022-12-31 13:17 出处:网络
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 under

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;
    }


You can use the Log property of the Provider class:

_db.Provider.Log = Console.Out;

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.


You can get the generated sql like this:

string sql = select.GetQueryText();

Make sure you are using the version 3.0.0.4 or above.

Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消