从Nlog异步连接到MySql数据库 [英] Async connection to MySql Database from Nlog
本文介绍了从Nlog异步连接到MySql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Nlog的新手.
我设法连接到MySql并将日志写到表中.
现在我要异步执行.
我将AsyncWrapper添加到了xml配置文件中.没有任何内容写入数据库.
我在自己的包装程序中添加了Flush().花了相同的时间-50条记录大约需要1分钟.
没有使用数据库执行此操作的示例,仅使用文件执行此操作,是否有人可以发布一个示例,说明如何与数据库有效地进行异步连接.
提前10倍
Jacob
Hi,
Im new to Nlog.
I manged to connecto to MySql and write logs to a table.
Now I want to do it Async.
I added AsyncWrapper to my xml configuration file. nothing was written to the DB.
I added Flush() in my own wrapper program. it took the same amount of time - approx 1 minute for 50 records.
There is no example of how to do it with DB, only with file, Can someone please post an example for Async connection to a DB that works.
10x in advance
Jacob
推荐答案
我不确定这是否是正确的方法,但是您可以尝试以下方法:
I''m not sure this is the right way to do it, but you can try this:
using System.ComponentModel;
using MySql.Data.MySqlClient;
public void Flush()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (sender, e) =>
{
// do some work, just an example
e.Result = MySqlHelper.ExecuteNonQuery("your-connectionstring-here", "your-commandtext-here");
// do some work
};
worker.RunWorkerCompleted += (sender, e) =>
{
MessageBox.Show((int)e.Result + " rows affected.", "Success");
};
worker.RunWorkerAsync();
}
这篇关于从Nlog异步连接到MySql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文