在C#中读写EventLog(事件日志)挺简单的,代码量也比较小。

1.加入System.Diagnostics Name Space;
 
EventLog(事件日志)的读写方法using System.Diagnostics;
2.声明一个EventLog类的实例。
 
EventLog eventLog;
eventLog
=new EventLog("TestEvent",".","mySource");
"TestEvent"是建立一个新的EventLog名,
".": 表示本机
"mySource": 源名
如果以上不设参数,就默认为"Application"

设好以后,就可以读写了。

写:
eventLog.Source="mySource";
eventLog.WriteEntry(
"Log text");
MessageBox.Show(
"Write Complete!")

读:
lstEvent.Items.Clear();
eventLog.Log
="TestEvent";
foreach(EventLogEntry eventlogEntry in eventLog.Entries)
{
lstEvent.Items.Add(eventlogEntry.Message);
}

相关文章:

  • 2021-12-13
  • 2021-05-22
  • 2021-12-28
  • 2022-03-02
  • 2021-07-02
  • 2022-01-26
  • 2021-11-10
猜你喜欢
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-09-08
  • 2021-12-05
相关资源
相似解决方案