我正在尝试使用EventLogReader
和EventRecord
类从本地计算机读取事件日志。使用 C#。
我不断收到错误
CS0236 错误:字段初始值设定项无法引用非静态字段、方法或属性“getInfo.BSN_Navigator”
不确定我做错了什么。
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.Eventing.Reader;
/// </var bank>
/// </var bank>
namespace EventLogInfoReader
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine();
String inputString = Console.ReadLine();
}
}
}
public class getInfo
{
public static PathType FilePath { get; private set; }
EventLogReader BSN_Navigator = new EventLogReader("c:\\Users\\banvilb\\Documents\\Event Log\\FalconBackup_Sep192016T124905\\BSN_Navigator.evt", FilePath);
EventRecord bsnRecord = BSN_Navigator.ReadEvent();
public void getLogName()
{
string x = bsnRecord.LogName;
Console.WriteLine(x);
}
public void getId()
{
int x = bsnRecord.Id;
Console.WriteLine(x);
}
}