I am trying to read an event log from my local computer using the EventLogReader
and EventRecord
classes. Using C#.
I keep getting the error
CS0236 Error: A field initializer cannot reference the non-static field, method, or property 'getInfo.BSN_Navigator'
Unsure what I am doing wrong.
Code:
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);
}
}