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
.NET
Microsoft Technologies based on the .NET software framework.
3,344 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 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.
10,199 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 4,662 Reputation points Microsoft Employee
    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.

    1 person found this answer helpful.

  2. 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(....). // error

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

    0 comments No comments