这是QuickStart里的事件日志监视示例,想把监视到的信息放到一个MDB数据库里(随便什么库结构,例子而已),而不是Console输出,要怎么做呀?谁帮帮我?using System;
using System.Diagnostics;
using System.Threading;public class LogMonitor
{
public static void Main(String[] args)
{
string appName = Environment.GetCommandLineArgs()[0]; if(args.Length != 1 && args.Length != 2) {
Console.WriteLine("用法:" + appName + " <log> [<machine>]");
Console.WriteLine ();
Console.WriteLine ("按 Enter 键继续...");
Console.ReadLine();
return;
}
string log = args[0];
string machine;
if(args.Length == 2)
{
machine= args[1];
}
else
{
machine = "."; // 本地计算机
} if(!EventLog.Exists(log,machine))
{
Console.WriteLine("日志不存在!");
return;
} EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine; aLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
aLog.EnableRaisingEvents = true; Console.WriteLine("按“q”退出该示例");
while(Console.Read()!='q')
{
Thread.Sleep(500);
}
} public static void OnEntryWritten(Object source, EntryWrittenEventArgs e) {
Console.WriteLine("已写入:" + e.Entry.Message);
}
}
using System.Diagnostics;
using System.Threading;public class LogMonitor
{
public static void Main(String[] args)
{
string appName = Environment.GetCommandLineArgs()[0]; if(args.Length != 1 && args.Length != 2) {
Console.WriteLine("用法:" + appName + " <log> [<machine>]");
Console.WriteLine ();
Console.WriteLine ("按 Enter 键继续...");
Console.ReadLine();
return;
}
string log = args[0];
string machine;
if(args.Length == 2)
{
machine= args[1];
}
else
{
machine = "."; // 本地计算机
} if(!EventLog.Exists(log,machine))
{
Console.WriteLine("日志不存在!");
return;
} EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine; aLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
aLog.EnableRaisingEvents = true; Console.WriteLine("按“q”退出该示例");
while(Console.Read()!='q')
{
Thread.Sleep(500);
}
} public static void OnEntryWritten(Object source, EntryWrittenEventArgs e) {
Console.WriteLine("已写入:" + e.Entry.Message);
}
}
SqlConnection sqlConn;
sqlConn.ConnectionString = "workstation id=CHEN;packet size=4096;user id=aa;data source=192.168.0.1;persist security info=True;initial catalog=Northwind;password=aa";//下面是插入语句,自己改成插入你的日志
SqlCommand cmd1=new SqlCommand("insert into TableName(a,b,c) values('','','')",sqlConn);
sqlConn.Open();//打开连接
cmd1.ExecuteNonQuery();//执行插入
sqlConn.Close();