using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using KREventLogCls;
namespace WriteLog
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
public void WriteLog(string sEvent)
...{
string sSource;
string sLog;
sSource = "mApp";
sLog = "mApplication";
KREventLogCls.KREventLogCls mWriteLog = new KREventLogCls.KREventLogCls();
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
//EventLog.Delete(sLog);
EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, 234);
}
private void button1_Click(object sender, EventArgs e)
...{
try
...{
WriteLog("写入成功");
}
catch (Exception ex)
...{
WriteLog("错误处理");
}
finally
...{
}
}
}
}在事件查看器中可以看到刚才写入的信息.
本文介绍了一个使用C#编写的简单应用程序,该程序能够向Windows事件查看器中写入自定义事件信息,并展示了如何创建事件源及写入不同类型的消息。
2439

被折叠的 条评论
为什么被折叠?



