Windows event logs are Windows only, and there is no direct equivalent on Linux. That's exactly why that API call gives you an exception on Linux. You will have to study what logging mechanism is used by Linux, such as syslog separately.
EventLog is not supports in Linux using .Net core 3.1
Hi,
I have an C#.net core 3.1 console application, it supports on Linux platform.
I need to get event log(like event viewer application logs in Windows) information from Linux , but i got runtime error:
Error:
Event Log not supports on Linux platform.
Please find the below code,
**EventLog log = new EventLog("Application");
Console.WriteLine("Application event log...");
for (int index = 0; index < log.Entries.Count; index++)
{
EventLogEntry entry = log.Entries[index];
Console.WriteLine("source " + entry.Source);
Console.WriteLine("Message " + entry.Message + " " + "Time " + entry.TimeWritten);
}**
Please help me on this issue.
How to get event logs from Linux using c#.net?
2 answers
Sort by: Most helpful
-
Lex Li (Microsoft) 4,662 Reputation points Microsoft Employee
2021-05-07T17:46:46.157+00:00 -
Bruce (SqlWork.com) 54,866 Reputation points
2022-08-03T18:40:12.163+00:00 on linux/unix logging is done by console output. this output is redirect to a log file or the system logging console. this is controlled by how the application is started.
so typically you would:
Console.WriteLine(....). // informational
Console.Error.WriteLine(....). // erroron linux a service is typically started by systemd, see its docs for managing a log files.