| 1 |
eventLog1.Log = "Application"; |
| 2 |
|
| 3 |
foreach (System.Diagnostics.EventLogEntry entry in eventLog1.Entries) |
| 4 |
{ |
| 5 |
Label.Text+=entry.Message; |
| 6 |
} |
查询:
using System.Diagnostics;
string ddd;
EventLog eventLog1 = new EventLog();
eventLog1.Log = "Application";
foreach (System.Diagnostics.EventLogEntry entry in eventLog1.Entries)
{
ddd= entry.Message;
int d = entry.EventID;
ddd=entry.UserName;
}
LINQ:
| 02 |
EventLog tLog = new EventLog(); |
| 04 |
tLog.Log = "Application"; |
| 06 |
//選出Type為Warring與Error,且時間介於選擇區間的Log |
| 08 |
from System.Diagnostics.EventLogEntry e2 in |
| 10 |
where (e2.EntryType == |
| 11 |
System.Diagnostics.EventLogEntryType.Warning || e2.EntryType == |
| 12 |
System.Diagnostics.EventLogEntryType.Error) && e2.TimeGenerated > |
| 13 |
dtpStart.Value && e2.TimeGenerated < dtpEnd.Value |
| 26 |
dataGridView1.DataSource = AppLogEntries.ToList(); |
写入:
using System.Diagnostics;
public void WriteToWindowsEvent(string aSource,string aMessage){
if(!EventLog.SourceExists(aSource)){
EventLog.CreateEventSource(aSource,"Project");
}
EventLog Log = new EventLog("Project");
oLog.Source = aSource;
oLog.WriteEntry(aMessage ,EventLogEntryType.Error);
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22392018/viewspace-704460/
,如需转载,请注明出处,否则将追究法律责任。