2016-09-06 79 views
1

我遇到了一个与我的应用程序有关的问题,我的一个要求是捕获postgres中输出的消息,当我调用PLPGSQL函数时,与此处发生的情况类似:通过npgsql获取postgres消息

Get warning messages through psycopg2

除了我的问题是在npgsql。我有我的日志管理器设置:

NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true); 

我做这样的判断:

_db.ExecuteScalar("SELECT test_warning();"); 

test_warning是一个自定义的SQL函数:

CREATE OR REPLACE FUNCTION test_warning() 
    RETURNS void AS 
$BODY$ 
begin 
raise info 'this is only a test'; 
end; 
$BODY$ 
    LANGUAGE plpgsql VOLATILE; 

_dbIDbConnection,和使用Dapper进行查询。在我的日志消息,我只得到调用的功能,以及一些其他的连接信息:

DEBUG [40560] Opened connection to (Database Server) 
TRACE [40560] Start user action 
TRACE [40560] ExecuteNonScalar 
DEBUG [40560] Executing statement(s): 

         SELECT test_warning() 
TRACE [40560] End user action 
TRACE [40560] Closing connection 
TRACE [40560] Really closing connection 
DEBUG [40560] Connection closed 

警告/信息消息没有提及。

+1

[注意信息处理(https://www.postgresql.org/ docs/current/static/libpq-notice-processing.html)如果您有权访问连接处理程序,那么它很简单。 – Abelisto

回答

0

首先,我会确保函数存在...我启动了postgres,并且无法运行该查询,因此它不是开箱即用的功能。

接下来,我会尝试调整我是怎么做的电话...

_db.CommandText = "SELECT test_warning()"; 
_db.ExecuteScalar(); 

这里的文档:http://www.npgsql.org/doc/index.html