EventLog is not supports in Linux using .Net core 3.1

Prabs 1 Reputation point
2021-05-06T05:44:00.497+00:00

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?

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
291 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,004 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
632 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: The period of time during which a program is being executed in a computer.
957 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 3,201 Reputation points
    2021-05-07T17:46:46.157+00:00

    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.


  2. Bruce (SqlWork.com) 28,276 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(....). // error

    on linux a service is typically started by systemd, see its docs for managing a log files.

    No comments