2016-09-06 58 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