c#读写系统事件日志
2015-08-25 14:54
423 查看
一、写入:
private void_writeLog(){
EventLog eventLog=newEventLog();
eventLog.Log = "LogName";
eventLog.Source = "ProjectName";
eventLog.WriteEntry("Message", EventLogEntryType.Error);
}
二、读取:
private void _readLog(){
EventLog eventLog=new EventLog();
eventLog.Log="Microsoft Office Sessions"; // 根据日志名读取
EventLogEntryCollectioneventList=eventLog.Entries; //获得所有信息
foreach (EventLogEntry logSingle in eventList){
this.writtenTimeTextBox=logSingle.TimeWritten.ToString();//写入日志时间
this.generateTimeTextBox=logSingle.TimeGenerated.ToString();//完成生成时间
this.messageTextBox.Text=logSingle.Message ;}}
private void_writeLog(){
EventLog eventLog=newEventLog();
eventLog.Log = "LogName";
eventLog.Source = "ProjectName";
eventLog.WriteEntry("Message", EventLogEntryType.Error);
}
二、读取:
private void _readLog(){
EventLog eventLog=new EventLog();
eventLog.Log="Microsoft Office Sessions"; // 根据日志名读取
EventLogEntryCollectioneventList=eventLog.Entries; //获得所有信息
foreach (EventLogEntry logSingle in eventList){
this.writtenTimeTextBox=logSingle.TimeWritten.ToString();//写入日志时间
this.generateTimeTextBox=logSingle.TimeGenerated.ToString();//完成生成时间
this.messageTextBox.Text=logSingle.Message ;}}
相关文章推荐
- 设计模式C#实现(四)——迭代器模式
- C# WebService动态调用
- C#的编译
- 分享c#写的 虚拟文件系统 开源库
- C# sliverlight调用WCF服务出现的一个错误
- C#实现将窗体固定在显示器的左上角且不能移动的方法
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- C#Base64编码的字符串与图片的转换
- 浅析C#中的Lambda表达式
- 浅析C#中的Lambda表达式
- The .NET weak event pattern in C#
- 浅析C#中的Func<>委托
- Winform(C#)Flash控件 属性 方法 事件
- 浅析C#中的Func<>委托
- C#性能优化考虑的几个方向
- C#读取DWG文件方法
- C#时间戳转换DateTime
- 对C#泛型实例化对像
- C#:向控件添加信息类
- Visual C#2010学习笔记八之out和ref的使用