What's the similar way to write event log when asp.net core app running on linux platform?

Xie Steven 831 Reputation points
2021-08-03T02:34:20.347+00:00

Hi,

My old ASP.NET Webform application use EventLog to write some information into windows event logs.

I know this API is only available in windows platform, so if my asp.net core mvc runs on linux, it will not work.

I want to know if there're some APIs whcih are available on windows and linux. Then, I can wirte event log like the old code logic.

Thanks

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-08-03T17:43:16.877+00:00

    There is no common api, this is why asp.net core uses an injected logger.

    The Unix convention is to write to a log file (stdout or path passed as arg) . Typically to folder in /var/log/

    You can also log to system logging (typically /var/log/system.log) by using posix api openlog() and syslog() (use pinvoke from c#)

    As you are probably going to run the asp.net core app with systemctl or systemd depending on Unix/Linux variant, you will want a logging provider that can write to a file.

    Your distribution may also have a log journaling feature. It will have its own api.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.