Reputation: 31
I am trying to read from the eventlog using visual studio 2019. I choose Console App(.NET CORE) for the project type. I use the following code.
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string eventLogName = "System";
EventLog eventLog = new EventLog();
eventLog.Log = eventLogName;
foreach (EventLogEntry log in eventLog.Entries)
{
Console.WriteLine("{0}\n", log.Message);
}
}
}
}
I get the following error.
CS1069. The type name 'EventLog' could not be found in the namespace 'System.Diagnostics.'This type has been forwarded to assembly.This type has been forwarded to assembly 'System.Diagnostics.EventLog, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.
How do I solve it?
Upvotes: 3
Views: 5202
Reputation: 481
You have to install a System.Diagnostics.EventLog Package.
You can Search & install this package System.Diagnostics.EventLog via Nuget Package Manager or you can install via cli https://www.nuget.org/packages/System.Diagnostics.EventLog/.
If you want to know in more detail go through this link GitHub Reference
I hope, your issue will resolve.
Upvotes: 5