You need to utilize systemd and Microsoft has a very detailed sample to guide you,
How to create service application in Linux using C#.Net Core 3.1?
Hi Team,
I have a C# .NET Core 3.1 console application which is running on terminal window in RedHat Linux.
It is a long running application. it runs 24/7.
I need to change from console to service application (like windows service in windows OS) which should running on background in Linux.
Could you please help me on this?
Regards,
Prabhakaran
4 answers
Sort by: Most helpful
-
Lex Li (Microsoft) 4,742 Reputation points Microsoft Employee
2021-07-28T14:49:37.087+00:00 -
Bruce (SqlWork.com) 56,846 Reputation points
2021-07-28T14:49:50.713+00:00 You can any console app with cron, or create a daemon process.
In Unix/Linux you create a daemon process, by disconnecting from the console. You do this by forking and redirecting stdout to a log file.
Fortunately ms has wrapped this up for with their service worker project type and UseSystemd(). See
-
Prabs 1 Reputation point
2021-07-30T11:47:55.137+00:00 Thanks team. I will test it out and come back if I face any issues.
-
Prabs 1 Reputation point
2021-08-02T06:48:32.17+00:00 Hello Team,
I have one new requirement.
When i run the sudo systemctl start testapp.service command, application has to wait for config file path provided by user.I tried the following code but it is not showing in Linux terminal window
Console.WriteLine("Enter config file path :");
string configFilepath = Console.ReadLine();Could you please help me on this?
Regards,
Prabs