I have an ASP.NET Core 8.0 Web API with a project reference to .NET 8.0 console app. An endpoint in the API controller calls the underlying console app (by direct method invocation and not by ProcessStart) to run some services. All the logging in the console app is done using Console.WriteLine.
I am worried if there will be concurrency issues if the same end point from controller is invoked multiple times in parallel calling the console app.
Controller call:
[HttpPost("SomeService")]
public string SomeService([FromBody] JsonObject jobParams)
{
return someService.InvokeSomeService(jobParams.ToString());
}
Console app service:
public class SomeService
{
public string InvokeSomeService(string json)
{
string originalOutput = Console.Out;
using (StringWriter stringWriter = new StringWriter())
{
try
{
string version = "1.0";
string logData = "";
Console.SetOut(stringWriter);
ServiceLogger.LogInformation($"***Start invoking the Some service {version}***");
Feeds feeds = new Feeds();
feeds.Start(json);
ServiceLogger.LogInformation($"***Completed running the Some service ***");
stringWriter.Flush();
logData = stringWriter.ToString();
feeds.SaveFeedsServiceLogs(logData);
return logData;
}
finally
{
Console.SetOut(originalOutput);
}
}
}
}