Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to Log All the queries with their parameter values

45 views
Skip to first unread message

Roshan Budhathoki

unread,
Dec 28, 2023, 2:36:29 PM12/28/23
to nhusers
I could log queries using Interceptor but paramerters are not being logged.

-------


public class NhibernateQueryLogger : EmptyInterceptor
{
    private Logger _logger;
    public NhibernateQueryLogger()
    {
        _logger = new LoggerConfiguration().WriteTo.RollingFile("logs/nhibernate-log-{Date}.txt").CreateLogger();
    }

    public override SqlString OnPrepareStatement(SqlString sql)
    {
        _logger.Information(sql.ToString());
        return base.OnPrepareStatement(sql);
    }
}

-----------------
Reply all
Reply to author
Forward
0 new messages