【发布时间】:2023-03-24 09:31:01
【问题描述】:
我发现了以下两种从远程服务器获取应用程序事件日志条目的方法。
1.使用 EventLog 对象
string logType = "Application";
EventLog ev = new EventLog(logType,"rspl200");
EventLogEntryCollection evColl = ev.Entries
2。使用 ManagementObjectSearcher 对象
ConnectionOptions co = new ConnectionOptions(); co.Username = "testA"; co.Password = "testA"; ManagementScope 范围 = new ManagementScope(@"\" + "machineName"+ @"\root\cimv2", co); scope.Connect();
SelectQuery query = new SelectQuery(@"select * from Win32_NtLogEvent"); EnumerationOptions opt = new EnumerationOptions(); opt.BlockSize = 1000;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query,opt))
{
foreach (ManagementObject mo in searcher.Get())
{
// write down log entries
Console.Writeline(mo["EventCode"]);
}
}
我可以使用方法 #1(使用 EventLog 对象)轻松获取远程事件日志,而不会出现任何安全访问被拒绝异常。但是使用方法#2(使用 ManagementObjectSearcher 对象)我得到拒绝访问异常。
实际上我希望远程事件日志(仅应用程序和最新日志而不是所有应用程序日志)显示在树形视图中,如下所示
- ServerName
- Logs
+ Error
+ Information
+ Warning
任何人都可以帮助我从这个或任何其他方面找出最好的方法吗?
Also the main thing is that user who reads remote logs may be in different domain than server.
谢谢 米特什·帕特尔
【问题讨论】: