我正在从 C# 可执行文件中启动 postgres 中的真空进程。我希望消息返回到我的可执行文件,但我无法从输出窗口取回消息。
简而言之,我正在使用 NPGSQL 在 postgres 中寻找与此等效的内容,例如:
// Display messages this code is for SQL server to reteive data back from message tab
conn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e) {
stdmForm.txtLastSQLMessages.Text +`=` "\n" + e.Message;
};
我想使用 NPGSQL 在我的 C# 代码中获取此消息。
最佳答案
我尝试了下面的代码。它会给你完整的执行日志。从这里我只是解析了我需要的日志。这不是最好的方法,但我找不到其他方法。
//log the Vacuum command information
NpgsqlEventLog.Level = LogLevel.Debug;
NpgsqlEventLog.LogName = VacuumLogFilePath + "rolling.log";
NpgsqlEventLog.EchoMessages = false;
try
{
//Run the Vacuum Command
NpgsqlCommand comm = new NpgsqlCommand("VACUUM VERBOSE ANALYZE", connection);
comm.ExecuteNonQuery();
}
关于c# - 从 postgres 取回消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753038/