这是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);
}
}
解决方案 »
- 一个关于视图和业务层分离的讨论,希望大家畅所欲言!
- 高手快快现身,看看我的钩子程序哪里错了?
- 初学者问题
- 比如我能读到一组数据 得出的值是 AA,BB,CC,DD其中的数值不固定 我想让他当Category=其中一个时 执行操作A 当Category不能于其中的数据时,执行操作B。代码该怎么写呢
- xml文件读取
- 大数据量的情况下如何是否进行对象的构建?
- 如何在WinForm中实现WebForm中的操作?
- 请问可以用代码来new 一个pictureBox吗?
- 请问如何创建一个目录?
- 关于类的意思
- 请问怎样UPdata(更新)DataSet表的行记录
- 简单,winform下的comboBox的数据绑定问题
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();