Tom*_*159 18 c# events logging
我正在尝试为我的应用程序EventLoggingApp读取事件日志.问题是为我的单一来源(EventLoggingApp)读取日志.
此代码读取每个源的日志.问题是什么?有什么建议?
static void ReadEvenLog()
{
string eventLogName = "Application";
string sourceName = "EventLoggingApp";
string machineName = "Tom";
EventLog eventLog = new EventLog();
eventLog.Log = eventLogName;
eventLog.Source = sourceName;
eventLog.MachineName = machineName;
foreach (EventLogEntry log in eventLog.Entries)
{
Console.WriteLine("{0}\n",log.Source);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 22
试试这个:
EventLog log = new EventLog("Security");
var entries = log.Entries.Cast<EventLogEntry>()
.Where(x => x.InstanceId == 4624)
.Select(x => new
{
x.MachineName,
x.Site,
x.Source,
x.Message
}).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46874 次 |
| 最近记录: |