gpt4 book ai didi

c# - 在 C# 中读取事件日志

转载 作者:可可西里 更新时间:2023-11-01 03:00:05 24 4
gpt4 key购买 nike

我正在尝试读取我的应用程序 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);
}
}

最佳答案

试试这个:

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();

关于c# - 在 C# 中读取事件日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3147972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com