0

I am getting the above mentioned error when I try to start the worker service on the target machine (windows server). I have tried everything, but without any success. I am still getting the error. I'm using .NET 6.0 and Microsoft.Extensions.Logging 6.0.0.

I have tried the fix at this Link which involved downgrading Microsoft.Extensions.Hosting and System.Diagnostics.EventLog to version 6.0.0, but this did not work.

Here is the code:

static async Task RunService()
{
  try
  {
    IHost host = Host.CreateDefaultBuilder().ConfigureServices(services =>
    {
      services.AddHostedService<Worker>();
    })
    .UseSystemd()
    .UseWindowsService()
    .Build();

    await host.RunAsync();

  catch (Exception ex)
  {
    Console.WriteLine(ex.ToString());
  }
}

I would be grateful if someone is able to help me.

Alexa Kirk
  • 152
  • 10
  • Why are you calling `UseSystemd`? – Stephen Cleary Jan 23 '23 at 20:23
  • @StephenCleary Because this application can be run on either a Linux or a Windows system. – Alexa Kirk Jan 23 '23 at 20:29
  • The mentioned answer actually clears all log providers and just `AddConsole` to override the default builder configuration. Have you tried it? – Vinícius Oliveira Jan 23 '23 at 21:11
  • @ViníciusOliveira. I did try to add this, but it won't compile stating that ```ILoggingBuilder does not contain a definition for 'ClearProviders'``` and the same message for ```AddConsole```. – Alexa Kirk Jan 23 '23 at 21:30
  • @AlexaKirk, those are extension methods, make sure to add `using Microsoft.Extensions.Hosting;` namespace and the equivalent nuget package into your project. – Vinícius Oliveira Jan 26 '23 at 20:20
  • @ViníciusOliveira All appropriate dlls are linked and the usings are correct. We cannot use nuget packages in our secure environment but the nuget packages have been downloaded, extracted, and their dlls are linked. This is not the issue. The issues is that I'm getting the referenced error. – Alexa Kirk Jan 30 '23 at 13:52

0 Answers0