Windows Event Log is a Windows-specific function, but .Net 5 is cross-platform. If you run this code on Linux, there will be problems.
The solution is simple, just add a judgment statement:
static void Main(string[] args)
{
if (OperatingSystem.IsWindows())
{
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1);
}
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.