question

LingSteven avatar image
0 Votes"
LingSteven asked Bruce-SqlWork edited

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

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

dotnet-aspnet-core-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork edited

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.