1

I am having an issue with my application, one of my requirements is to capture the messages that is output in postgres when I make a call to a PLPGSQL function, similarly to what is happening here:

Get warning messages through psycopg2

Except my issues are in npgsql. I have my log manager set up:

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

And I make this call:

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

test_warning is a custom sql function:

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

and _db is the IDbConnection, and the query is made using Dapper. In my log messages, I am only getting the call to the function, as well as some other connection information:

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

No mention of the warning/info message.

Community
  • 1
  • 1
Steve Pak
  • 152
  • 1
  • 13
  • 1
    [Notice Processing](https://www.postgresql.org/docs/current/static/libpq-notice-processing.html) If you have the access to the connection handler then it is simple. – Abelisto Sep 06 '16 at 22:28

1 Answers1

0

First, I'd ensure that function exists... I fired up postgres and could not run that query, so it's not an out of the box function.

Next, I'd try adjusting how I was making the call...

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

Here's the docs: http://www.npgsql.org/doc/index.html

Steven Mays
  • 365
  • 1
  • 12